Iptables block ip address – Security Shell Script

in Categories Firewall last updated December 20, 2008

Create /root/iptables/blocked.ips file as follows with list of ips and subnets to block entering your dedicated server:

Call following script from your existing shell script:

Share this on:

9 comment

  1. thanks for this script..
    btw i have some error with “BADIPS=$(egrep -v -E “^#|^$” /root/iptables/blocked.ips)”
    with -E swich… i change it to -e and its work fine
    in egrep –help no -E option

    ubuntu 10.04

  2. I think rule
    is incorrect. Because in this case $ipblock is destination (-d), not source (-s)

    1. Dear Reader.
      you can remove IP from block by this short command
      #iptables -D input -s IP ADDRESS -j DROP is an example you can remove any IP that you want just type instate

    Have a question? Post it on our forum!