今日有個網絡攻擊模擬需求,要打分片的ip包,程序寫好了,在開發機上驗證也沒問題,然后部署到沙盒環境之后不行,就是發不出來數據包,而不分片的數據包能夠正常發送,定位過程如下
1.對比了兩台機器/proc/sys/net/ipv4下的ip相關參數的值,都一樣,忽略了因為ipfrag相關設置帶來的影響。
2. 查看dmesg、/var/log/messages,沒有什么異常的日志。
3. 查看netstat -s
Ip: 226610920001 total packets received 957 with invalid addresses 0 forwarded 0 incoming packets discarded 226610067704 incoming packets delivered 588767879431 requests sent out 20609816 outgoing packets dropped 43646 dropped because of missing route 42 fragments dropped after timeout 353567514 reassemblies required 42 packet reassembles failed
其中飄紅的這一樣,按照50w/s的速率遞增,大致知道了是內核丟掉了數據包,猜測的原因是:內核設定了重組數據包,等待發送來的后續數據包,一直沒等到。
4. 搞網卡的參數
ethtool -K xgbe0 tso off ethtool -K xgbe0 gso off ethtool -K xgbe0 gro off ethtool -K xgbe0 lrf off
5. 之后數據包能發出來10s不到,數據包又發不出來了。
6. 考慮是內核相關的東西,查看各內核模塊發現有nf_defrag_ipv4模塊,手工去掉所有相關模塊
rmmod iptable_nat nf_nat
rmmod nf_conntrack_ipv4 nf_conntrack nf_defrag_ipv4
rmmod iptable_filter ip_queue nfnetlink iptable_mangle ip_tables x_tables
7.搞定
總結:解決問題的過程中並沒有完全搞清楚各種現象的根本原因以及牽涉到知識的根本,需要繼續補充