如果我输入 iptables -L
输出中有这一行:
Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:http-alt
我的容器是公开的,我可以从任何地方请求一个虚拟的 http 服务器(经过测试)。我尝试删除该规则,因此只有 80 只暴露在我的服务器内(
localhost:80
)。我试过了 :root@ns25252:~# iptables -D DOCKER --destination 172.17.0.2 -p tcp --dport 80 -j ACCEPT
iptables: Bad rule (does a matching rule exist in that chain?).
正如错误所暗示的那样,它找不到匹配的规则。我应该如何键入以删除该行?
最佳答案
按编号删除通常更容易,除非在您列出规则和删除规则期间编号可能会发生变化。
以下是按行号删除的方法:
# iptables -L --line-numbers
(snip)
Chain DOCKER (2 references)
num target prot opt source destination
1 ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:http
(snip)
# iptables -D DOCKER 1
或者,您可以通过执行
iptables -S
获得完整的规范。例子:# iptables -S
(snip)
-A DOCKER -d 172.17.0.2/32 -p tcp -m tcp --dport 80 -j ACCEPT
(snip)
将
-A
转换为 -D
并将其用作 iptables
的参数以删除规则:# iptables -D DOCKER -d 172.17.0.2/32 -p tcp -m tcp --dport 80 -j ACCEPT
关于docker - 无法删除docker容器的默认iptables规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50084582/