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
Comments on this entry are closed.
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.
Yuriy is 100% correct.
It’s a common mistake to lose ssh this way…