Iptables is a  firewall on linux  os.You can manage your ınput and output traffic with a lots of properties.You can use iptables like a router, nat or proxy too.

There are three default chain comes with  iptables.These are

Input:You can arrenge packets that comes to your computer.

Forward:You can arrrange packets that forwarded on your computer.

Output:You can arrange your output packets from your computer.

Processes to packets: Drop, reject, accept or forwarding another  chaine . We will check having  rpm packets or not.

1

Iptables rules define on at this file.

 

2

 

3

 

Listing the rules

4

 

 

 

 

We can define with -P (policy) iptables chain situation.Such as drop input packets.

5

 

 

 

As you see policy is dropped.

We can delete all rule in a chain.

# -f flush

6

 

 

 

Adding rule to the end of the chain

7

 

 

 

We can add rule on a chain which line we want.

8

 

 

As you see we  add 2. INPUT  rule is DROP

We can create new chain with this command

9

 

 

 

Deleting a rule on the chain

We add a rule to NewChain and then deleted it

10

 

 

 

 

 

Deleting the chain

11

 

 

 

 

When we define rules, we can add more option too, such as protocol source ip source port likely destination ip and port.

–sport  – = source port and if you use “!” this mean expect this port.

–dport  – = destination port

İf you use icmp protocol, you filter according to icmp packet type

–icmp-type

-ı  and -o parametres are using to define which interface us it.-ı  UNPUT, -o OUTPUT

We can define rules to iptables, we are able to write rules according to its situation.

NEW:first packet that side start to connection

RELATED:Sended packet  depend on an old  established connection.

ESTABLİSHED:Packet that depend on established connection

INVALID: Packets that doesn’t depend on any connection.

-j define the actions such as;

DROP, REJECT, ACCEPT, CHAIN

12

 

 

 

We can saved he rules that defined with “iptables-save” command and we can write this rules to a  file for making our rule permanent.

13

 

 

 

We can save with “service iptables save” too.

I will take a copy of my rules for restoring.I can use these command another host or I can restore my iptables with this command.

14

 

 

 

These are basic configuration of iptables you can more info on man page of iptables. Type to your console:

or read this page;

ManPage

Good luck!