tc命令,模擬網(wǎng)絡(luò)異??赏ㄟ^以下命令,其中eth0可根據(jù)自己的網(wǎng)卡設(shè)備號進(jìn)行替換:
1. 網(wǎng)絡(luò)延遲
?tc qdisc add dev eth0 rootnetem delay 100ms
該命令將?eth0?網(wǎng)卡的傳輸設(shè)置為延遲?100?毫秒發(fā)送。
模擬更真實的情況,延遲值可能會有一定的波動性,可以使用以下命令來模擬
tc qdisc add dev eth0 root netem delay 100ms 10ms
該命令將?eth0?網(wǎng)卡的傳輸設(shè)置為延遲?100ms ± 10ms?(90 ~ 110 ms?之間的任意值)發(fā)送
2. 網(wǎng)絡(luò)丟包
tc qdisc add dev eth0 root netem loss 1%
該命令將?eth0?網(wǎng)卡的傳輸設(shè)置為隨機(jī)丟掉?1%?的數(shù)據(jù)包。
3. 數(shù)據(jù)包重復(fù)
tc qdisc add dev eth0 root netem duplicate 1%
該命令將?eth0?網(wǎng)卡的傳輸設(shè)置為隨機(jī)產(chǎn)生?1%?的重復(fù)數(shù)據(jù)包 。
4. 數(shù)據(jù)包損壞
tc qdisc add dev eth0 root netem corrupt 0.2%
該命令將?eth0?網(wǎng)卡的傳輸設(shè)置為隨機(jī)產(chǎn)生?0.2%?的損壞的數(shù)據(jù)包 。
5. 數(shù)據(jù)包亂序
tc qdisc change dev eth0 root netem delay 10ms reorder 25% 50%
該命令將?eth0?網(wǎng)卡的傳輸設(shè)置為:有?25%?的數(shù)據(jù)包(50%相關(guān))會被立即發(fā)送,其他的延遲10?秒。
查看已經(jīng)配置的網(wǎng)絡(luò)條件
tc qdisc show dev eth0
如果需要刪除已配置的條件,則將以上命令中的add更改為del即可。
當(dāng)然iptables還是可以模擬丟包,很多人說tc用起來更方便,但是tc是基于網(wǎng)卡的操作,而iptables是可以基于指定的ip進(jìn)行丟包處理,這無非是使用虛機(jī)的小伙伴們的福音啦~
參考:
https://blog.csdn.net/wuxiaobingandbob/article/details/72765633
iptables
https://blog.csdn.net/sheldon761642718/article/details/54602864