sábado, 16 de agosto de 2014

Iptables block ip address – Security Shell Script


by  on DECEMBER 20, 2008 ·
Create /root/iptables/blocked.ips file as follows with list of ips and subnets to block entering your dedicated server:
192.168.1.0/24
202.54.1.2
# spam
202.5.1.2



Call following script from your existing shell script:
  1. #!/bin/bash
  2. # Simple iptables IP/subnet block script
  3. # -------------------------------------------------------------------------
  4. # Copyright (c) 2004 nixCraft project <http://www.cyberciti.biz/fb/>
  5. # This script is licensed under GNU GPL version 2.0 or above
  6. # -------------------------------------------------------------------------
  7. # This script is part of nixCraft shell script collection (NSSC)
  8. # Visit http://bash.cyberciti.biz/ for more information.
  9. # ----------------------------------------------------------------------
  10. IPT=/sbin/iptables
  11. SPAMLIST="spamlist"
  12. SPAMDROPMSG="SPAM LIST DROP"
  13. BADIPS=$(egrep -v -E "^#|^$" /root/iptables/blocked.ips)
  14. # create a new iptables list
  15. $IPT -N $SPAMLIST
  16. for ipblock in $BADIPS
  17. do
  18. $IPT -A $SPAMLIST -s $ipblock -j LOG --log-prefix "$SPAMDROPMSG"
  19. $IPT -A $SPAMLIST -s $ipblock -j DROP
  20. done
  21. $IPT -I INPUT -j $SPAMLIST
  22. $IPT -I OUTPUT -j $SPAMLIST
  23. $IPT -I FORWARD -j $SPAMLIST

No hay comentarios:

Publicar un comentario