How to View and Delete Iptables Rules – List and Flush

by SathiyaMoorthy on July 16, 2010

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

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

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

{ 1 comment… read it below or add one }

1 Yuriy July 1, 2013 at 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.

Leave a Comment

Previous post:

Next post: