tc

一 tc 最简单例子

http://blog.csdn.net/duanbeibei/article/details/41250029/1、模拟延迟传输

# tc  qdisc  add  dev  eth0  root  netem  delay  100ms

二 开启ifb0 ifb1

http://blog.csdn.net/eydwyz/article/details/53085690

modprobe ifb

启用虚拟设备ifb0。 

#ip link set dev ifb0 up

 

三、可以限速的命令

root@ubuntu:/home/wang/git# tc qdisc del dev enp0s3 root
root@ubuntu:/home/wang/git# tc qdisc add dev enp0s3 root handle 1: htb default 2
root@ubuntu:/home/wang/git# 
root@ubuntu:/home/wang/git# tc class add dev enp0s3 parent 1:1 classid 1:2 htb rate 10mbit ceil 100mbit prio 2
root@ubuntu:/home/wang/git# tc class add dev enp0s3 parent 1:1 classid 1:3 htb rate 5mbit ceil 2mbit prio 2
root@ubuntu:/home/wang/git# tc filter add dev enp0s3 protocol ip parent 1:0 u32 match ip src 192.168.0.113 flowid 1:2
root@ubuntu:/home/wang/git# tc filter add dev enp0s3 protocol ip parent 1:0 u32 match ip src 192.168.0.113 flowid 1:2

  

对所有ip的

root@ubuntu:/home/wang/git# tc qdisc del dev enp0s3 root
root@ubuntu:/home/wang/git# tc qdisc add dev enp0s3 root handle 1: htb default 2
root@ubuntu:/home/wang/git# tc class add dev enp0s3 parent 1:1 classid 1:2 htb rate 10mbit ceil 100mbit prio 2
root@ubuntu:/home/wang/git# tc class add dev enp0s3 parent 1:1 classid 1:3 htb rate 5mbit ceil 2mbit prio 2
root@ubuntu:/home/wang/git# tc filter add dev enp0s3 protocol ip parent 1: prio 50 u32 match ip dst 0.0.0.0/0 flowid 1:10

  

ifb0的第一次起作用

root@ubuntu:/home/wang/git# tc qdisc del dev enp0s3 ingress
root@ubuntu:/home/wang/git# tc qdisc add dev enp0s3 ingress
root@ubuntu:/home/wang/git# tc filter add dev enp0s3 parent ffff: protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb0
root@ubuntu:/home/wang/git# 
root@ubuntu:/home/wang/git# tc qdisc add dev ifb0 root netem delay 200ms

 标准的起作用 要记住ifb0的方向性//to thi tha式子,那边把20 33换换 反正前两句话没问题

tc qdisc add dev enp0s3 handle ffff: ingress
tc filter add dev enp0s3 parent ffff: protocol all prio 5 u32 match u32 0 0 flowid 10:10 action mirred egress redirect dev ifb0
  

tc qdisc add dev ifb0 root handle 1: htb default 2
tc class add dev ifb0 parent 1:1 classid 1:2 htb rate 10mbit ceil 10mbit prio 2
tc class add dev ifb0 parent 1:1 classid 1:3 htb rate 5mbit ceil 2mbit prio 2

tc filter add dev ifb0 protocol ip parent 1:0 u32 match ip src 192.168.0.113 flowid 1:2
tc filter add dev ifb0 protocol ip parent 1:0 u32 match ip src 192.168.0.101 flowid 1:3

  

tc qdisc add dev enp0s3 handle ffff: ingress
tc filter add dev enp0s3 parent ffff: protocol all prio 5 u32 match u32 0 0 flowid 10:10 action mirred egress redirect dev ifb0

tc qdisc add dev ifb0 root handle 1:0 htb
tc class add dev ifb0 parent 1:1 classid 1:2 htb rate 10mbit ceil 20mbit prio 2
tc filter add dev ifb0 protocol ip parent 1: prio 50 u32 match ip dst 0.0.0.0/0 flowid 1:10

1:2一样效果

 

 

最小组合

 

tc qdisc del dev ifb0 root
tc qdisc del dev enp0s3 ingress

tc qdisc add dev enp0s3 handle ffff: ingress
tc filter add dev enp0s3 parent ffff: protocol all prio 5 u32 match u32 0 0 flowid 10:10 action mirred egress redirect dev ifb0
  

tc qdisc add dev ifb0 root handle 1: htb default 2
tc class add dev ifb0 parent 1:1 classid 1:2 htb rate 10mbit ceil 10mbit prio 2

 

 

改装的成功的

tc qdisc add dev enp0s3 handle ffff: ingress
tc filter add dev enp0s3 parent ffff: protocol all prio 5 u32 match u32 0 0 flowid 10:10 action mirred egress redirect dev ifb0
 
tc qdisc add dev ifb0 root handle 1: htb default 2
tc class add dev ifb0 parent 1:0 classid 1:2 htb rate 2500.000kbit ceil 2500.000kbit prio 1

 

posted @ 2017-09-06 20:55  cnchengv  阅读(86)  评论(0)    收藏  举报