How To Flush/Remove All Iptables Rules In Linux

by lifeLinux on May 19, 2011

By default iptables firewall stores its configuration at /etc/sysconfig/iptables file. Type the following command to see its

# cat /etc/sysconfig/iptables


Or

# iptables -L

Temporarily delete all the firewall rules

At first, create flush.iptables script with following command

# vi flush.iptables

Add the following content

#!/bin/sh
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

Finally, run flush.iptables script with the following command

# sh flush.iptables

After running flush.iptables script, if you restart the iptables, you’ll see all the default rules again. So, flush is only temporary.

Permanently remove all the default firewall rules

Step 1. Flush all these rules temporarily, as we discussed above.
Step 2. Saving firewall rules to /etc/sysconfig/iptables. Type the following command

# /etc/init.d/iptables save

Or

# iptables-save > /etc/sysconfig/iptables

Related Posts:

Previous post:

Next post: