#!/usr/bin/env bash # th(at)bogus.net # the interfaces you defined in badlink.sh INTERFACES="ens18 ens19" for i in $INTERFACES do tc qdisc del dev $i root done root@wanem:~# cat badlink.sh #!/usr/bin/env bash # th(at)bogus.net # most of this was borrowed from # https://wiki.linuxfoundation.org/networking/netem # the interfaces on which you want this traffic shaping INTERFACES="ens18 ens19" # WAN link parameters (VSAT links typically have between 550-650ms latency) # DELAY_MS should be half, as we do traffic control on ingress and egress interfaces DELAY_MS=275 RATE_MBIT=0.5 LOSS_PC=15 DUPLICATE_PC=5 CORRUPT_PC=1 if [ $(which bc) = "" ] then echo "error: bc required, on debian, run apt -y install bc" exit 1 fi BUF_PKTS=100 BDP_BYTES=$(echo "($DELAY_MS/1000.0)*($RATE_MBIT*1000000.0/8.0)" | bc -q -l) BDP_PKTS=$(echo "$BDP_BYTES/1500" | bc -q) LIMIT_PKTS=$(echo "$BDP_PKTS+$BUF_PKTS" | bc -q) for i in $INTERFACES do tc qdisc add dev $i root netem delay 100ms tc qdisc replace dev $i root netem delay ${DELAY_MS}ms rate ${RATE_MBIT}Mbit limit ${LIMIT_PKTS} tc qdisc change dev $i root netem delay ${DELAY_MS}ms 40ms 25% loss ${LOSS_PC}% 25% duplicate ${DUPLICATE_PC}% corrupt ${CORRUPT_PC}% done