简体   繁体   English

如何阻止与在主机上的 docker 容器中创建的 IP 的连接

[英]How to block the connection to an IP which is created in docker container on host

There is a docker container running in bridge network mode.有一个 docker 容器以桥接网络模式运行。 Inside the container, it creates a connection to, say, 10.123.123.1:6666 .在容器内部,它会创建一个到10.123.123.1:6666的连接。 I'd like to block this connection on host through IPTABLES, something like sudo iptables -I OUTPUT -p tcp -d 10.123.123.1 -j DROP , but it doesn't work.我想通过 IPTABLES 阻止主机上的此连接,例如sudo iptables -I OUTPUT -p tcp -d 10.123.123.1 -j DROP ,但它不起作用。 Could anyone help me on this please?有人可以帮我吗?

I can't even see this connection on host by command netstat -an , but I can see it inside the container.我什至无法通过命令netstat -an在主机上看到此连接,但我可以在容器内看到它。

I don't have to use IPTABLES, but I can't change the configuration of the docker running.我不必使用 IPTABLES,但无法更改正在运行的 docker 的配置。

These packets are going through INPUT & OUTPUT chains in the container's network namespace, and not in the host's network namespace.这些数据包在容器的网络命名空间中通过 INPUT 和 OUTPUT 链,而不是在主机的网络命名空间中。

All your host network namespace does is forward these packets so you need to alter the FORWARD chain with a rule similar to iptables -I FORWARD -p tcp -d 10.123.123.1 -j DROP .您的主机网络命名空间所做的只是转发这些数据包,因此您需要使用类似于iptables -I FORWARD -p tcp -d 10.123.123.1 -j DROP的规则来更改 FORWARD 链。 Bear in mind that Docker alters iptables rules which may punch holes in the firewall.请记住,Docker 会更改 iptables 规则,这可能会在防火墙上打孔。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用容器名称从主机操作系统解析 docker 容器 IP - Resolve docker container IP from host OS using container name 以编程方式从 Docker 容器中获取主机的 ip 和 Python - Programmatically get host's ip from within Docker container with Python "如何将主机目录挂载到正在运行的 docker 容器中" - How to mount a host directory into a running docker container 如何在 linux 主机上运行 windows docker 容器? - How to run a windows docker container on linux host? 无法从同一局域网中的另一台主机ping Docker容器 - Can not ping docker container from another host which is in the same LAN Docker 组合设置 Linux Docker 主机 ZA12A3079E14CED46E69BA52B8A90B2 中的地址 - Docker Compose Set Linux Docker Host IP Address in Container's /etc/hosts 执行从 docker 容器到主机的端口映射时,如何修复“curl (56) Recv failure: Connection reset by peer”错误? - How to fix "curl (56) Recv failure: Connection reset by peer" error when doing a port mapping from docker container to host machine? 从容器内获取 docker 网络的私有 ip 以配置 xdebug remote_host - Geting the private ip for the docker network from within the container to configure xdebug remote_host 如何在mac OS中将主机IP地址传递给docker? - How to pass host ip address to docker in mac OS? 使用--device标志时,主机上创建的新设备节点不会反映在Docker容器中 - New device node created on host does not get reflected in Docker container when using --device flag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM