Iptables block ip address – Security Shell Script

Posted on 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:

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
    $IPT -I OUTPUT -j $SPAMLIST
    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 172.20.7.12 IP ADDRESS -j DROP
      172.20.7.12 is an example you can remove any IP that you want just type instate

Leave a Comment