wiki:AdminGuides/Iptables

Linux Firewall (iptables) Basics

iptables is most common application to control Linux firewall. Here are quick steps to manipulate iptables:

Block IP (add to iptables)

to add ip address, execute following command:

iptables -A INPUT -s <ip_address> -j DROP

For example, to block IP address 10.1.1.2, the command will be:

iptables -A INPUT -s 10.1.1.2 -j DROP

List currently blocked IPs by iptables

iptables --list --line-numbers -n | grep DROP

theoutput will be like:

1    DROP       all  --  10.1.1.2       0.0.0.0/0 
2    DROP       all  --  192.168.1.22       0.0.0.0/0 
3    DROP       all  --  192.168.1.95       0.0.0.0/0 

the first column is the entry order number. It can be useful to remove entries from list.

Unblock (remove) IP address from iptables

first get the entry number with above list command. Then remove from list:

iptables -D INPUT <linenumber>

in above command replace <linenumber> with number from list command. For example, to unblock ip address 192.168.1.22, the command will be:

iptables -D INPUT 2

Then check with list command if the Ip was removed.

Last modified 7 years ago Last modified on Mar 11, 2011, 4:42:58 PM