如何删除这个 iptables 规则?

Mil*_*los 0 linux debian iptables

我有一个 iptables 规则。搜索它时

sudo /sbin/iptables -L -n --line-numbers
Run Code Online (Sandbox Code Playgroud)

我明白了

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
...
Run Code Online (Sandbox Code Playgroud)

我的目标是删除此规则。

我试过

sudo iptables -D INPUT 2
Run Code Online (Sandbox Code Playgroud)

但规则仍然存在。我在 debian 上。任何的想法?

r_3*_*r_3 10

您正在尝试删除 chain 的规则 2 INPUT,您的规则存储在 chain 中tcp_inbound


leu*_*cos 5

查找要删除的规则的最简单方法是检查 的输出iptables-save,更改-A-D要删除的规则。

在你的情况下:

$ iptables-save | grep 10.10.0.20
....
-A tcp_inbound -s 10.10.0.20/32 -p tcp -m tcp --dport 25 -j ACCEPT
....
Run Code Online (Sandbox Code Playgroud)

所以你只需要发出:

iptables -D tcp_inbound -s 10.10.0.20/32 -p tcp -m tcp --dport 25 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)