IPTABLES – blocking IPs simplified

By | November 7, 2008

You can block an IP from IPTABLES by using

iptables -I INPUT -s -j DROP

You can simplify things a little bit by using a shell script and a predefined text file containing the IPs we want to be blocked. Either create a new file or add the following at the end of the script which activates the firewall:


for i in $(< bad_hosts.lst) ; do

iptables -I INPUT -i eth1 -s “$i” -j DROP


Now create a new file in the same directory and name it bad_hosts.lst and add a new IP to be blocked on every single line, like in the example below:

One thought on “IPTABLES – blocking IPs simplified

Leave a Reply

Your email address will not be published. Required fields are marked *