调试iptables

开启调试iptables的内核模块

modprobe nf_log_ipv4
sysctl net.netfilter.nf_log.2=nf_log_ipv4

添加iptables trace规则

# raw只在PREROUTING和OUTPUT才有
iptables -t raw -A PREROUTING -p icmp -j TRACE
iptables -t raw -A OUTPUT -p icmp -j TRACE

启动容器后验证

docker run -itd busybox:1.36 sh

tail -f /var/log/messages

从宿主机上ping容器IP
发送流程
OUTPUT->POSTROUTING->docker0->容器网卡
响应流程
容器网卡->docker0->PREROUTING->INPUT

恢复

iptables -t raw -D PREROUTING 1
iptables -t raw -D OUTPUT 1
modprobe -r nf_log_ipv4

参考资料

Linux中调试 iptables

 

posted on   王景迁  阅读(195)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示