如何使用iptables阻止docker容器端口?
我使用docker服务设置容器网络。我只需为目标ip打开一个端口7035,并将其公开给主机。如何使用iptables阻止docker容器端口?,docker,iptables,Docker,Iptables,我使用docker服务设置容器网络。我只需为目标ip打开一个端口7035,并将其公开给主机。 当我用“iptables-nvL”检查iptables时 我看到了前链: Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 DROP tcp
当我用“iptables-nvL”检查iptables时 我看到了前链:
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DROP tcp -- * * 0.0.0.0/0 172.18.0.2 tcp dpt:7053
1680K 119M DOCKER-ISOLATION all -- * * 0.0.0.0/0 0.0.0.0/0
1680K 119M DOCKER all -- * br-287ce7f19804 0.0.0.0/0 0.0.0.0/0
1680K 119M ACCEPT all -- * br-287ce7f19804 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
和DOCKER链:
Chain DOCKER (4 references)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- !br-287ce7f19804 br-287ce7f19804 0.0.0.0/0 172.18.0.2 tcp dpt:7053
0 0 ACCEPT tcp -- !br-287ce7f19804 br-287ce7f19804 0.0.0.0/0 172.18.0.2 tcp dpt:7051
0 0 ACCEPT tcp -- !br-287ce7f19804 br-287ce7f19804 0.0.0.0/0 172.18.0.3 tcp dpt:2181
0 0 ACCEPT tcp -- !br-287ce7f19804 br-287ce7f19804 0.0.0.0/0 172.18.0.4 tcp dpt:7053
0 0 ACCEPT tcp -- !br-287ce7f19804 br-287ce7f19804 0.0.0.0/0 172.18.0.4 tcp dpt:7051
0 0 ACCEPT tcp -- !br-287ce7f19804 br-287ce7f19804 0.0.0.0/0 172.18.0.6 tcp dpt:7053
0 0 ACCEPT tcp -- !br-287ce7f19804 br-287ce7f19804 0.0.0.0/0 172.18.0.6
我想封锁172.18.0.2号集装箱,港口是7053。所以我使用了sudo iptables-I FORWARD-ptcp-d172.18.0.2--dport 7053-j DROP
但是,它不起作用。
那么,我应该如何阻止目标ip和端口呢?以下操作应该有效:
iptables -I DOCKER 1 -p tcp --dport 7053 -j DROP
这将在DOCKER链中的所有其他规则之前插入DROP规则
以下是一个非常有用的命令:
iptables --list DOCKER -n --line
同样,如果您添加-v
(详细),您将获得更多详细信息
到目前为止,你可能已经有了答案,但它可能会帮助其他人