≡ Menu

Iptables block ip address – Security Shell Script

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 comments… add one }
  • Erik January 16, 2012, 10:53 pm

    i have a ip that i want to block 78.47.53.243 in my dreambox ???

    please..

  • gamecp March 30, 2011, 2:58 pm

    great script!

  • dodger July 5, 2010, 12:34 pm

    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

  • peace February 23, 2010, 8:51 pm

    hi i new to iptables where exactly should i write this script any help
    please
    thanks for any help appreciated.

  • Andre October 28, 2009, 6:53 pm

    i wanna allow just this ip [10.0.0.100 – 10.0.0.112, 10.0.0.2, 10.0.0.3] and block other ip how is the configuration.
    please send to my email : nseshop@gmail.com

    thanks very much

  • parbat June 24, 2009, 1:05 pm

    hi

    everybody now will come big platform

  • Charon June 19, 2009, 12:45 pm

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

  • Igor May 29, 2009, 12:55 am

    How can I remove ip’s from blocked

    • Ghulam Sakhi June 29, 2011, 10:49 am

      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

Security: Are you a robot or human?

Leave a Comment