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, the command will be:

iptables -A INPUT -s -j DROP

List currently blocked IPs by iptables

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

theoutput will be like:

1    DROP       all  -- 
2    DROP       all  -- 
3    DROP       all  -- 

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, the command will be:

iptables -D INPUT 2

Then check with list command if the Ip was removed.

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