docker - 如何防止 docker 容器访问我的本地网络

标签 docker iptables ebtables

我希望能够阻止连接到桥接网络的 docker 容器访问我的本地网络,以增加额外的安全性,因为它们可以从外部访问(以防容器受到损害)。我发现我可能应该使用 ebtables 或 iptables 的 physdev 模块,但我无法创建有效的规则。感谢能帮助我的人。

最佳答案

经过一些研究,如果有人感兴趣,可以使用 ebtables。

# Authorize DNS queries
ebtables -A INPUT -p IPV4 --ip-protocol TCP --ip-destination-port 53 --ip-destination 192.168.1.1 --ip-source 172.18.0.0/16 -j ACCEPT
ebtables -A INPUT -p IPV4 --ip-protocol UDP --ip-destination-port 53 --ip-destination 192.168.1.1 --ip-source 172.18.0.0/16 -j ACCEPT
# Drop all others packets
ebtables -A INPUT -p IPV4 --ip-destination 192.168.1.0/24 --ip-source 172.18.0.0/16 -j DROP

不要忘记将 172.18.0.0/16 子网替换为容器所连接的子网。

关于docker - 如何防止 docker 容器访问我的本地网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72037768/

相关文章:

mysql - Docker Mysql容器root密码【mysql监听端口0】

mysql - 用户 'root' @'172.28.1.5' 的 Docker 访问被拒绝(使用密码 : NO))

docker - 使用 Nginx 反向代理时无法获取客户端的真实 IP

centos - 在谷歌计算引擎中打开特定端口。 [centos7]

linux - 如何使用 ebtables 或 ptables 丢弃具有特定 MAC 地址的数据包?

docker - 使用环境变量从另一个Docker容器访问本地SQS服务

linux - 关于IPSET的查询

linux - Docker 容器内的动态监听端口

ubuntu - 如何解决 Windows 10 Spring Creators Update 上 Ubuntu 中的运行级别错误?