ryan4yin / thiscute.world

Ryan4Yin's Space
https://thiscute.world
17 stars 3 forks source link

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

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

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

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

gethurb commented 2 years ago

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

ryan4yin commented 2 years ago

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

YuJunping commented 1 year ago

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

ryan4yin commented 1 year ago

@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

ryan4yin commented 1 year ago

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

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

YuJunping commented 1 year ago

OK,谢谢!

原始邮件

发件人:"Ryan Yin"< @.*** >;

发件时间:2023/3/15 16:56

收件人:"ryan4yin/thiscute.world"< @.*** >;

抄送人:"YuJunping"< @. >;"Mention"< @. >;

主题:Re: [ryan4yin/thiscute.world] posts/iptables-and-container-networks/(Issue #14)

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

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

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>