tc限速配置

#TC 限速
#https://blog.csdn.net/zhongbeida_xue/article/details/54613750
#https://blog.51cto.com/13162375/2112847
#https://blog.csdn.net/eydwyz/article/details/53320612
#https://lartc.org/howto/lartc.qdisc.classful.html

#!/bin/bash
WANDEV=eth0
LANDEV=eth1
ALLOUT=200mbit
EVERYIPOUT=100mbit
ALLIN=200mbit
EVERYIPIN=100mbit

#上传速率做流量控制
tc qdisc del dev $WANDEV root 2>/dev/null
#根队列
tc qdisc add dev $WANDEV root handle 1:0 htb default 60
#根类
tc class add dev $WANDEV parent 1:0 classid 1:1 htb rate $ALLOUT ceil $ALLOUT prio 0
#子类
tc class add dev $WANDEV parent 1:1 classid 1:11 htb rate $EVERYIPOUT ceil $EVERYIPOUT prio 1 burst 96kbit
#设置队列规则
tc qdisc add dev $WANDEV parent 1:11 handle 111:0 sfq perturb 10
tc filter add dev $WANDEV parent 1:0 protocol ip prio 1 u32 match ip src 192.168.122.0/24 flowid 1:11


#做下载限制,过滤器是用u32
tc qdisc del dev $LANDEV root 2>/dev/null
#根队列
tc qdisc add dev $LANDEV root handle 2:0 htb default 30
#根类
tc class add dev $LANDEV parent 2:0 classid 2:1 htb rate $ALLIN ceil $ALLIN prio 0
#子类
tc class add dev $LANDEV parent 2:1 classid 2:11 htb rate $EVERYIPIN ceil $EVERYIPIN prio 1
#设置队列规则
tc qdisc add dev $LANDEV parent 2:11 sfq perturb 10
tc filter add dev $LANDEV parent 2:0 protocol ip prio 2 u32 match ip dst 192.168.122.0/24 flowid 2:11

#查看流量
#tc -s qdisc ls dev eth0
#tc -s qdisc ls dev eth1
#tc -s class ls dev eth0
#tc -s class ls dev eth1

posted @ 2019-09-24 17:34  larry-peng  阅读(2020)  评论(0编辑  收藏  举报