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

by on April 24, 2008 · 6 comments

 
#!/bin/bash
# Linux Firewall: Simple Shell Script To Stop and Flush All Iptables Rules
# Some Linux distros like Debian do not have /etc/init.d/iptables stop script
# This can be also called from cron job if you are testing new firewall on
# remote box to avoid lock out
# -------------------------------------------------------------------------
# Copyright (c) 2004 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

{ 6 comments… read them below or add one }

1 Sandeep February 18, 2009

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

2 Vivek Gite February 28, 2009
3 Fred November 26, 2009

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?

4 Vivek Gite November 28, 2009

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
cd
sudo ~/script
5 John Jones May 6, 2010

Thanks guy this was really help full, Linux rules

6 Bekir YAPAR July 8, 2010

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

Leave a Comment

You can use these HTML tags and attributes for UNIX commands or shell scripts: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 10 + 7 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a script.



Tagged as: bash linux, firewall iptables, flush firewall script, iptables command, linux distros, linux firewall, shell script, stop firewall script

Previous Script:

Next Script: