Linux – How to remove this iptables rule

debianiptableslinux

I have an iptables rule. When searching for it with

sudo /sbin/iptables -L -n --line-numbers

I am getting it

Chain tcp_inbound (1 references)
num  target     prot opt source               destination
xxxx
2    ACCEPT     tcp  --  10.10.0.20           0.0.0.0/0           tcp dpt:25
xxxx
...

My goal is to delete this rule.

I tried with

sudo iptables -D INPUT 2

But the rule is still there. I am on debian. Any idea?

Best Answer

The easiest way to find which rule to delete is to check the output of iptables-save, and change -A to -D is the rule you want to remove.

In your case :

$ iptables-save | grep 10.10.0.20
....
-A tcp_inbound -s 10.10.0.20/32 -p tcp -m tcp --dport 25 -j ACCEPT
....

So you just need to issue :

iptables -D tcp_inbound -s 10.10.0.20/32 -p tcp -m tcp --dport 25 -j ACCEPT