Linux下用tc控制网络延时和丢包率

来源:互联网 发布:php pdf完整版 编辑:程序博客网 时间:2024/05/01 00:05

 

tc修改网络延时:  

sudo tc qdisc add dev eth0 root netem delay 1000ms


删除策略:

sudo tc qdisc del dev eth0 root netem delay 1000ms


 

验证效果:

PING myhost (192.168.0.2) 56(84) bytes of data.
64 bytes from myhost (192.168.0.2): icmp_seq=1 ttl=64 time=1000 ms

64 bytes from myhost (192.168.0.2): icmp_seq=1 ttl=64 time=1000 ms

64 bytes from myhost (192.168.0.2): icmp_seq=1 ttl=64 time=1000 ms


修改丢包率:
sudo tc qdisc add dev eth0 root netem loss 10%

删除策略:
sudo tc qdisc del dev eth0 root netem loss 10%

=====================================================================

  • 查看流量管理   tc     qdisc    show
  • 配置网络延时:
  • # tc qdisc del dev eth0 root netem loss 10%[root@AutoTest ~]# tc qdisc showqdisc pfifo_fast 0: dev eth0 root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1[root@AutoTest ~]# tc qdisc add dev eth0 root netem delay 1000ms [root@AutoTest ~]# ping 192.168.0.1PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=2001 ms64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=1001 ms^C--- 192.168.0.1 ping statistics ---6 packets transmitted, 5 received, 16% packet loss, time 5846msrtt min/avg/max/mdev = 1000.520/1200.819/2001.001/400.092 ms, pipe 3[root@AutoTest ~]# tc qdisc del dev eth0 root netem delay 1000ms [root@AutoTest ~]# ping 192.168.0.1PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.465 ms64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.546 ms^C--- 192.168.0.1 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1841msrtt min/avg/max/mdev = 0.465/0.505/0.546/0.046 ms[root@AutoTest ~]# 
    • 配置网络丢包率
    • # tc qdisc del dev eth0 root netem loss 10%RTNETLINK answers: Invalid argument[root@AutoTest ~]# tc qdisc add dev eth0 root netem loss 10%[root@AutoTest ~]# tc qdisc showqdisc netem 8005: dev eth0 root refcnt 2 limit 1000 loss 10%[root@AutoTest ~]# ping 192.168.0.1 -n 20PING 20 (0.0.0.20) 56(124) bytes of data.^C--- 20 ping statistics ---7 packets transmitted, 0 received, 100% packet loss, time 6371ms[root@AutoTest ~]# ping 192.168.0.1 -c 20PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.533 ms64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.506 ms64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=0.471 ms64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=0.550 ms64 bytes from 192.168.0.1: icmp_seq=7 ttl=64 time=0.474 ms64 bytes from 192.168.0.1: icmp_seq=8 ttl=64 time=0.499 ms64 bytes from 192.168.0.1: icmp_seq=10 ttl=64 time=0.541 ms64 bytes from 192.168.0.1: icmp_seq=11 ttl=64 time=0.470 ms64 bytes from 192.168.0.1: icmp_seq=12 ttl=64 time=0.531 ms64 bytes from 192.168.0.1: icmp_seq=13 ttl=64 time=0.476 ms64 bytes from 192.168.0.1: icmp_seq=14 ttl=64 time=0.503 ms64 bytes from 192.168.0.1: icmp_seq=15 ttl=64 time=0.508 ms64 bytes from 192.168.0.1: icmp_seq=16 ttl=64 time=0.541 ms64 bytes from 192.168.0.1: icmp_seq=19 ttl=64 time=0.531 ms64 bytes from 192.168.0.1: icmp_seq=20 ttl=64 time=0.536 ms--- 192.168.0.1 ping statistics ---20 packets transmitted, 15 received, 25% packet loss, time 19999msrtt min/avg/max/mdev = 0.470/0.511/0.550/0.033 ms# tc qdisc del dev eth0 root netem loss 10%[root@AutoTest ~]# ping 192.168.0.1 -c 20PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.827 ms64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.508 ms64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=0.506 ms64 bytes from 192.168.0.1: icmp_seq=4 ttl=64 time=0.574 ms64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=0.555 ms64 bytes from 192.168.0.1: icmp_seq=6 ttl=64 time=0.495 ms64 bytes from 192.168.0.1: icmp_seq=7 ttl=64 time=0.517 ms64 bytes from 192.168.0.1: icmp_seq=8 ttl=64 time=0.529 ms64 bytes from 192.168.0.1: icmp_seq=9 ttl=64 time=0.515 ms64 bytes from 192.168.0.1: icmp_seq=10 ttl=64 time=0.571 ms64 bytes from 192.168.0.1: icmp_seq=11 ttl=64 time=0.508 ms64 bytes from 192.168.0.1: icmp_seq=12 ttl=64 time=0.533 ms64 bytes from 192.168.0.1: icmp_seq=13 ttl=64 time=0.526 ms64 bytes from 192.168.0.1: icmp_seq=14 ttl=64 time=0.520 ms64 bytes from 192.168.0.1: icmp_seq=15 ttl=64 time=0.532 ms64 bytes from 192.168.0.1: icmp_seq=16 ttl=64 time=0.549 ms64 bytes from 192.168.0.1: icmp_seq=17 ttl=64 time=0.527 ms64 bytes from 192.168.0.1: icmp_seq=18 ttl=64 time=0.575 ms64 bytes from 192.168.0.1: icmp_seq=19 ttl=64 time=0.534 ms64 bytes from 192.168.0.1: icmp_seq=20 ttl=64 time=0.556 ms--- 192.168.0.1 ping statistics ---20 packets transmitted, 20 received, 0% packet loss, time 19000msrtt min/avg/max/mdev = 0.495/0.547/0.827/0.074 ms[root@AutoTest ~]# 

原创粉丝点击