rss logo

How to delete a Netfilter rule with iptables

Here's a method to easily delete a rule under the Netfilter firewall with the iptables command.




List current rules

First we list our current rules :

root@host:~# iptables --line-numbers -L -n -v -t filter
root@host:~# iptables --line-numbers -L -n
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --              state RELATED,ESTABLISHED
2    ACCEPT     icmp --             
3    ACCEPT     all  --             
4    ACCEPT     udp  --            state NEW udp dpt:5353
5    REJECT     all  --              reject-with icmp-host-prohibited
6    ACCEPT     tcp  --              tcp dpt:22


Here we delete the rule n°6 of the INPUT chain :

root@host:~# iptables -t filter -D INPUT 6

We can also delete the same rule using this command :

root@host:~# iptables -D INPUT -m tcp -p tcp --dport 22 -j ACCEPT
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address