Linux使用tc对网络进行限速.md
一、限制向特定IP端的出流量outgoing
tc qdisc del dev eth0 root 2>/dev/null
tc qdisc add dev eth0 root handle 2:0 htb default 30
tc class add dev eth0 parent 2:0 classid 2:11 htb rate 20Mbit ceil 20Mbit prio 1
tc filter add dev eth0 parent 2:0 protocol ip prio 2 u32 match ip dst 10.140.0.0/16 flowid 2:11
tc filter add dev eth0 parent 2:0 protocol ip prio 2 u32 match ip dst 10.0.3.11/32 flowid 2:11
解除限制
tc qdisc del dev eth0 root
限制从特殊IP段的入流量incoming
modprobe ifb numifbs=1
ip link set ifb0 up
# redirect ingress to ifb0
tc qdisc add dev eth0 ingress handle ffff:
tc filter add dev eth0 parent ffff: protocol ip prio 0 u32 match u32 0 0 flowid ffff: action mirred egress redirect dev ifb0
# add qdisc
tc qdisc add dev ifb0 root handle 2:0 htb default 30
# add default class
tc class add dev ifb0 parent 2:0 classid 2:11 htb rate 20Mbit ceil 20Mbit prio 1
# add ingress rules for 192.168.0.9
tc filter add dev ifb0 parent 2:0 protocol ip prio 2 u32 match ip src 172.28.0.93/32 flowid 2:11
解除限制
tc qdisc del dev ifb0 root
tc qdisc del dev eth0 ingress
modprobe -r ifb
三、默认的tc qdisc规则
[root@ab-ipcpu-com-01 ~]# tc qdisc
qdisc noqueue 0: dev lo root refcnt 2
qdisc 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@ab-ipcpu-com-01 ~]#
#@每个网卡都会产生一条
转载请注明:IPCPU-网络之路 » Linux使用tc对网络进行限速