HowTo: Flush Iptables Under Ubuntu Linux

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

ADVERTISEMENTS

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

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • vicank Jul 3, 2014 @ 14:02

    It worked like a charm..
    Thanks a lot.. :)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.