Linux Firewall: Simple Shell Script To Stop and Flush All Iptables Rules

by on April 24, 2008 · 6 comments

  2. #!/bin/bash
  3. # Linux Firewall: Simple Shell Script To Stop and Flush All Iptables Rules
  4. # Some Linux distros like Debian do not have /etc/init.d/iptables stop script
  5. # This can be also called from cron job if you are testing new firewall on
  6. # remote box to avoid lock out
  7. # -------------------------------------------------------------------------
  8. # Copyright (c) 2004 nixCraft project <>
  9. # This script is licensed under GNU GPL version 2.0 or above
  10. # -------------------------------------------------------------------------
  11. # This script is part of nixCraft shell script collection (NSSC)
  12. # Visit for more information.
  13. # -------------------------------------------------------------------------
  14. iptables -F
  15. iptables -X
  16. iptables -t nat -F
  17. iptables -t nat -X
  18. iptables -t mangle -F
  19. iptables -t mangle -X
  20. iptables -P INPUT ACCEPT
  21. iptables -P OUTPUT ACCEPT
  22. iptables -P FORWARD ACCEPT

4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • Sandeep

    Hi Vivek,

    Could you please post a script on iptables rules for a webserver so that instead of APF or CSF you can just run this script daily or as per scheduled with a cron job.

    Thank you

  • Vivek Gite
  • Fred

    Silly question, but where should I save this script to in Debian? And how can I run it without having to mention ./location/location/script all the time?

  • Vivek Gite

    You can store it in your own ~/bin directory and add to the PATH in ~/.bash_profile:

    mkdir ~/bin
    cp script ~/bin
    cd ~/bin
    chmod +x script
    echo "export PATH=$PATH:~/bin" >> ~/.bash_profile
    export PATH=$PATH:~/bin
    sudo ~/script
  • John Jones

    Thanks guy this was really help full, Linux rules

  • Bekir YAPAR

    Thx. For help. İt’s helpfull for us.

Previous Script:

Next Script: