Posted By

mladoux on 09/21/10


Tagged

Bash linux utility rc


Versions (?)

IP Tables Start/Stop Script


 / Published in: Bash
 

URL: http://mark.haktstudios.com/

Simple RC script for starting and stopping IP Tables, place it in your init.d

  1. #!/bin/sh
  2. #
  3. # firewall Start/Stop iptables firewall
  4. #
  5. # Author: Mark A. LaDoux <[email protected]>
  6. #
  7.  
  8. set -e
  9.  
  10. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  11.  
  12. SCRIPTNAME=/etc/init.d/$NAME
  13.  
  14. # Gracefully exit if the package has been removed.
  15. test -x $DAEMON || exit 0
  16.  
  17. case "$1" in
  18. start)
  19. echo -n "Starting iptables firewall"
  20. iptables-restore < /etc/firewall.conf
  21. echo "."
  22. ;;
  23. stop)
  24. echo -n "Stopping iptables firewall"
  25. iptables -F
  26. iptables -X
  27. iptables -t nat -F
  28. iptables -t nat -X
  29. iptables -t mangle -F
  30. iptables -t mangle -X
  31. iptables -P INPUT ACCEPT
  32. iptables -P FORWARD ACCEPT
  33. iptables -P OUTPUT ACCEPT
  34. echo "."
  35. ;;
  36. save)
  37. echo -n "Saving iptables firewall configuration"
  38. rm -rf /etc/firewall.conf
  39. iptables-save > /etc/firewall.conf
  40. echo "."
  41. ;;
  42. *)
  43. echo "Usage: $SCRIPTNAME {start|stop|save}" >&2
  44. exit 1
  45. ;;
  46. esac
  47.  
  48. exit 0

Report this snippet  

You need to login to post a comment.