调试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 2023-06-09 15:06  王景迁  阅读(168)  评论(0编辑  收藏  举报

导航