HowTo: Flush Iptables Under Ubuntu Linux

last updated in Categories

How do I flush all IPv4 and IPv6 iptables rules under Ubuntu Linux?

To see your current rules in iptables (IPv4), enter:
$ sudo iptables -L
To see your current rules in ip6tables (IPv6), enter:
$ sudo ip6tables -L

How Do I Disable (flush) IPv4 Firewall?

If you need to disable the firewall, you can flush all the rules using the following command:
$ sudo iptables -F
Create a shell script as follows (say /root/stop.fw) :

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

Run it as follows:
$ sudo chmod +x /root/stop.fw
$ sudo /root/stop.fw
$ sudo iptables -L

How Do I Disable (flush) IPv6 Firewall?

If you need to disable the firewall, you can flush all the rules using the following command:
$ sudo ip6tables -F
Create a shell script as follows (say /root/stop6.fw) :

#!/bin/sh
IPT6="/sbin/ip6tables"
echo "Stopping IPv6 firewall..."
$IPT6 -F
$IPT6 -X
$IPT6 -Z
for table in $(</proc/net/ip6_tables_names)
do
        $IPT6 -t $table -F
        $IPT6 -t $table -X
        $IPT6 -t $table -Z
done
$IPT6 -P INPUT ACCEPT
$IPT6 -P OUTPUT ACCEPT
$IPT6 -P FORWARD ACCEPT

Run it as follows:
$ sudo chmod +x /root/stop6.fw
$ sudo /root/stop6.fw
$ sudo ip6tables -L

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 1 comments/add one below):

1 comment

    Have a question? Post it on our forum!