如果要对所有出站流量应用限制,则完全不需要过滤器。只需将qdisc添加到接口根句柄即可,如下所示:
tc qdisc add dev eth0 root handle 1: tbf rate 256mbit latency 1ms burst 1540
如果您想调整/调整入站流量,则要复杂一些。您需要使用例如IFB接口:
modprobe ifb
ip link set dev ifb0 up
tc qdisc add dev eth0 ingress
tc filter add dev eth0 parent ffff: protocol ip u32 match u32 0 0 action mirred egress redirect dev ifb0
# ^- this is a dummy filter, match u32 0 0 matches all traffic
tc qdisc add dev ifb0 root handle 1: tbf rate 256mbit latency 1ms burst 1540
这是使用两种简单过滤器的另一种方法:
tc qdisc add dev eth0 ingress
tc filter add dev eth0 root protocol ip u32 match u32 0 0 police rate 256mbit burst 10k drop flowid :1
tc filter add dev eth0 parent ffff: protocol ip u32 match u32 0 0 police rate 256mbit burst 10k drop flowid :1