Easy way to delete rule from iptables

Valic —  January 28, 2012 — 1 Comment
You can view iptables entries by line with command:
iptables -L INPUT -n --line-numbers
Example:

[email protected]:~# iptables -L INPUT -n –line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  –  0.0.0.0/0            192.168.1.100       tcp dpt:22
2   ACCEPT     tcp  –  0.0.0.0/0            192.168.1.100       tcp dpt:80
3    ACCEPT     tcp  –  0.0.0.0/0            192.168.1.100       tcp dpt:443
4    ACCEPT     tcp  –  0.0.0.0/0            192.168.1.100       tcp dpt:21
5   ACCEPT     all  –  127.0.0.1            0.0.0.0/0
6   ACCEPT     all  –  192.168.1.100        0.0.0.0/0
7   ACCEPT     icmp –  0.0.0.0/0            0.0.0.0/0
8   ACCEPT     all  –  192.168.4.0/24       0.0.0.0/0
9   DROP       all  –  0.0.0.0/0            0.0.0.0/0           state NE

You’ll get the list of all INPUT entries.  Look at the number on the left  then use the following command to delete :

iptables -D INPUT <<number here>>

Enjoy.

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

One response to Easy way to delete rule from iptables

  1. Wiley Mihelich January 28, 2012 at 22:43

    Your writing is great:)

Leave a Reply