≡ Menu

How to View and Delete Iptables Rules – List and Flush

Question: How do I view all the current iptables rules? Once I view it, is there a way to delete all the current rules and start from scratch?

Answer: Use the iptables list option to view, and iptables flush option to delete all the rules as shown below. You should have root permission to perform this operation.

1. View / List All iptables Rules

When you want to check what rules are in iptables, use –list option as shown below.

# iptables --list

Example 1: Iptables list output showing no rules

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

The above output shows chain headers. As you see, there are no rules in it.

Example 2: Iptables list output showing some rules

When there is a rule to disable ping reply, you have the iptables list output as like the following. You can see the rule in the OUTPUT chain.

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
DROP       icmp --  anywhere             anywhere            icmp echo-request

2. Delete iptables Rules using flush option

When you want to delete all the rules, use the flush option as shown below.

# iptables --flush

After doing this, your iptables will become empty, and the “iptables –list” output will look like what is shown in the example 1.

You can also delete (flush) a particular iptable chain by giving the chain name as an argument as shown below.

# iptables --flush OUTPUT
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Yuriy July 1, 2013, 1:40 am

    Never do iptables rules –flush, as it is provided in article.
    If you have DROP rule for INPUT chain you will lose your connectivity with server if you are using ssh.
    Before –flush you must implement ACCEPT policy for INPUT chain.

  • Stiven Andre May 29, 2014, 4:59 am

    Yuriy is 100% correct.
    It’s a common mistake to lose ssh this way…