| tags:iptables linux security sysadmin categories:Tech

Delete IPtables Rule

To list the rule list with numbers:

iptables -L <chain name> -n --line-numbers

[root@server ~]# iptables -L INPUT -n --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3306
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:555
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
[root@server ~]#

To delete a rule:

iptables -D <chain name> <line number>

[root@server ~]# iptables -D INPUT 1

Result:

[root@bryanw ~]# iptables -L INPUT -n --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:555
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
[root@bryanw ~]#