弱网环境构造

# cat net-env.sh   
#!/bin/bash

ip_1=xxx.xxx.xxx.xxx
ip_2=xxx.xxx.xxx.xxx

tc qdisc add dev eth0 root handle 1: htb

tc class add dev eth0 parent 1: classid 1:11 htb rate 20000Mbit
tc class add dev eth0 parent 1: classid 1:12 htb rate 20000Mbit

tc filter add dev eth0 parent 1:0 protocol ip  prio 1 u32 match ip dst ${ip_1} flowid 1:11
tc filter add dev eth0 parent 1:0 protocol ip  prio 1 u32 match ip dst ${ip_2} flowid 1:12

# 随机丢失25%数 50% 丢失成功 10%重包 25%数据准时到达 50%延时100ms
tc qdisc add dev eth0 parent 1:11 netem loss 25% 50% duplicate 10% delay 100ms reorder 25%  50%
tc qdisc add dev eth0 parent 1:12 netem loss 25% 50% duplicate 10% delay 100ms reorder 25%  50%

int=1
while(( $int<=60*15 ))
do
    echo $int
    let "int++"
    sleep 1
done

# 清空 eth0网卡根目录的队列规则
tc qdisc del dev eth0 root
 

你可能感兴趣的:(弱网环境构造)