How to List and Delete Iptables Rules

Iptables is a kind of firewall which is by default available in all Linux distributions. When you install any distro of Linux, iptable would be surely there but, it is programmed in a way that it allows all the traffic by default. There is lot more information available on iptables, but most of them are very complex and if you just want to have a look at basic things like Listing or Deleting iptable rules then this article is for you.

Iptables are normally used to setup, maintain and inspect the tables of packet filter rules in your Linux kernel. You have an option to delete more than one rule from any selected chain. As a brand new user of Linux iptables and you don’t know how to delete or list or unblock any IP address in iptables? You can find some basic commands here which will help us to list or delete the rules.

Very basic thing is to use list option with iptable command to view all the rules and flush option with iptables to delete all the rules. Below mentioned are the examples to perform the same. You are required to have root privileges to perform this operation.

To View/List all rules in iptables

# iptables –list

Note: when you want to check which the rules in iptables are then you can use the above mentioned options.

List output having 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 output shown above shows different chain headers in iptables. There are no rules present.

Eg. To List output having some rules in iptables

For instance, there is a rule which disables ping reply; you can view the output of iptables like following. You can find this 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 INPUT (policy ACCEPT)
Target prot opt source destination
DROP icmp -- anywhere anywhere icmp echo-request

Delete iptables rules with flush option

When you are looking to delete all the rules, you can easily use flush option as shown below.

# iptables –flush

After performing this command your iptable will become completely empty, and if you try to look at the output of iptables –list command then the output would look like show in the first example above. You can also delete a particular chain of iptables by specifying the name of chain as an argument in the command. Example is show below:

# iptables –flush OUTPUT

This example would completely delete the output chain from the iptables you have created.
Eg. You also have an option to delete the iptable rule with its line number. Below is an example to denote the same.

# iptables –L INPUT –line-numbers
Chain INPUT (policy ACCEPT)
Num target prot opt source destination
1 ACCEPT udp -- anywhere anywhere udp dpt:domain
2 ACCEPT tcp -- anywhere anywhere tcp dpt:domain
. . .

So, now if you want to delete the second rule from above then:

# iptables –D INPUT 2


In this tutorial we learned how to list and delete iptables rules in Linux. Hope you enjoyed reading and please add your suggestion on the below comment section.

Bobbin Zachariah 9:37 pm

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author's All Posts
Like to become part of Linoxide Team and contribute tips? Contact us here.


Your email address will not be published. Required fields are marked *

All comments are subject to moderation.