我希望能够阻止连接到桥接网络的 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/