Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posts/iptables-and-container-networks/ #14

Open
utterances-bot opened this issue May 8, 2022 · 6 comments
Open

posts/iptables-and-container-networks/ #14

utterances-bot opened this issue May 8, 2022 · 6 comments

Comments

@utterances-bot
Copy link

iptables 及 docker 容器网络分析 - This Cute World

https://thiscute.world/posts/iptables-and-container-networks/

Copy link

gethurb commented May 8, 2022

您好,有个疑惑希望向您请教下,容器的iptables规则是否独立于宿主机?我测试看了下LOG,容器中的流量并没有经过任何宿主机的iptables链,直到从docker0中出来。

@ryan4yin
Copy link
Owner

@gethurb 是指在 iptables 里加了些 LOG 规则?Docker 实际上会在 nat 跟 filter 两个表中创建好几个自定义链。具体的 iptables 规则在这篇文章的第二节有给出来的。

Copy link

您好!,-A POSTROUTING -s 172.18.0.2/32 -d 172.18.0.2/32 -p tcp -m tcp --dport 80 -j MASQUERADE 这条规则的作用是什么,什么情况下会被匹配到,一直没弄明白。

@ryan4yin
Copy link
Owner

ryan4yin commented Mar 4, 2023

@YuJunping 这你可真问到我了,研究了一波发现我也没搞明白...

源地址与目标地址都是 172.18.0.2/32,说明是容器在请求它自己,为什么自己请求自己还要做 NAT(MASQUERADE) 呢???

只要容器内的协议栈实现没毛病,请求它自己的 ip 地址根本不会走网桥,直接就走本地了,我抓包验证了请求容器自身 ip 时网桥上确实是没流量的。

查了下找到这里有遇到同样的问题 Docker Implementation of Published Ports, 这个老外表示: Please don't ask me under what scenario one might hit those rules...

感觉是很边缘的情况,如果你有什么发现可以留言沟通 emmm

Copy link
Owner

@YuJunping 这个特殊 iptables 规则的问题我之前在 0xffff 开了个帖子,有大佬给了些有用的信息,你可以看看:

https://0xffff.one/d/1450-docker-duan-kou-ying-she-shi-xian

@YuJunping
Copy link

YuJunping commented Mar 15, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants