iptables-banlist init.d script
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          iptables-banlist
  4. # Required-Start:    $local_fs $network
  5. # Required-Stop:     $local_fs $network
  6. # Should-Start:
  7. # Should-Stop:
  8. # Default-Start:     2 3 4 5
  9. # Default-Stop:      0 1 6
  10. # Short-Description: iptables-banlist
  11. ### END INIT INFO
  12.  
  13. set -e
  14.  
  15. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  16.  
  17. . /lib/lsb/init-functions
  18.  
  19. case "$1" in
  20. start)
  21.  
  22. iptables -t filter -A INPUT -s 10.0.0.0/24 -j ACCEPT
  23.  
  24. if [ -f /root/iptables-banlist ]
  25. then
  26.  
  27. for BAN in $(cat /root/iptables-banlist)
  28. do
  29. iptables -t filter -A INPUT -s $BAN -j DROP
  30. done
  31.  
  32. echo "iptables-banlist DONE"
  33. beep -f 1000 -l 1000
  34.  
  35. else
  36. echo "FAILED! - file /root/iptables-banlist does not exist!"
  37. fi
  38. ;;
  39.  
  40. reload)
  41. if [ -f /root/iptables-banlist ]
  42. then
  43.  
  44. iptables -F INPUT
  45. iptables -t filter -A INPUT -s 10.0.0.0/24 -j ACCEPT
  46.  
  47. for BAN in $(cat /root/iptables-banlist)
  48. do
  49. iptables -t filter -A INPUT -s $BAN -j DROP
  50. done
  51.  
  52. echo "IPTABLES custom chains reloaded"
  53. beep -f 1000 -l 1000
  54.  
  55. else
  56. echo "FAILED! - file /root/iptables-banlist does not exist!"
  57. fi
  58. ;;
  59.  
  60. unban-all|stop)
  61. iptables -F
  62. beep -f 1000 -l 1000
  63. echo "IPTABLES chains flushed"
  64. ;;
  65.  
  66. status)
  67. echo "IPTABLES chains printout:"
  68. iptables -L
  69. ;;
  70.  
  71. *)
  72. echo "Usage: /etc/init.d/iptable-ban.sh {start|reload|unban-all|status}"
  73. ;;
  74. esac
  75. exit 0
Parsed in 0.014 seconds