How to: Linux flush or remove all iptables rules

by LinuxTitli on June 20, 2005 · 6 comments

Here is small script that does this. Debian or Ubuntu GNU/Linux does not comes with any SYS V init script (located in /etc/init.d directory) .

You create a script as follows and use it to stop or flush the iptables rules.

Please don't type rules at command prompt. Use the script to speed up work.

Procedure for Debian / Ubuntu Linux

A) Create /root/fw.stop /etc/init.d/fw.stop script using text editor such as vi:

#!/bin/sh
echo "Stopping firewall and allowing everyone..."
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 FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

(B) Make sure you can execute the script:
# chmod +x /root/fw.stop

(C) You can run the script:
# /root/fw.stop

A note for RedHat and friends Linux user

Please note that RedHat enterprise Linux (RHEL) and Fedora / Centos Linux comes with pre-installed script, which can be used to stop the firewall:
#/etc/init.d/iptables stop

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 6 comments… read them below or add one }

1 JRivera September 20, 2008

#/etc/init.d/iptables stop

Thank you that just saved me much time.

Reply

2 Phil Nutzmeyer September 11, 2009

Thanks!!! It saved my time too!

Reply

3 noob December 26, 2009

should i run update-rc.d on the script in init.d ?
Or will the script be run automatically when the system is booted up ?

thanx.

Reply

4 phpmonk March 22, 2010

iptables normally starts when you start system
‘/etc/init.d/iptables status’ should show you rules of iptables running.

Reply

5 Relax June 6, 2011

iptables –flush
iptables –delete-chain
iptables –table nat –flush
iptables –table filter –flush
iptables –table nat –delete-chain
iptables –table filter –delete-chain

Reply

6 rocksfrow October 26, 2011

In CentOS 5 I easily disable iptables after installation as root:

#service iptables stop
#chkconfig iptables off

chkconfig ensures iptables doesn’t start up next boot.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 9 + 15 ?
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 bot.




Previous post:

Next post: