Flushing all the tables in the firewall

How do I flush all the iptables (IPv4) tables in the firewall using command line ssh session?

## Flush Any Existing Rules or Chains...

# Reset Default Policies
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P OUTPUT ACCEPT

# Flush all rules
iptables -F ; iptables -t nat -F ; iptables -t mangle -F

# Erase all non-default chains
iptables -X ; iptables -t nat -X ; iptables -t mangle -X

## Done.

Check my blog post

Sorry, I forgot one table up there – “raw”.
So, flushing all rules and erasing all non-default chains:

for i in  filter nat mangle raw  ;do
   iptables -t $i -F ; iptables -t $i -X
done

Although pre tag is nice. For code and script use the following syntax
```
my code
goes here
```

You are even more OCD than me.  :-)
I use the pre tag when my intention is to not 
have any highlighting or unintended smileys.

And just for fun… :slight_smile:
#!/bin/bash

for i in  filter nat mangle raw  ;do
   for j in  F  X  ;do
      iptables -t $i -$j
   done
done

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki