我正在尝试监管给定端口的下游带宽 - 但似乎除非我有巨大的限制和突发,否则下载完全停止
IF="wlp3s0"
LIMIT="100kbit"
BURST="100kbit"
PORT="80"
echo "resetting tc"
tc qdisc del dev ${IF} ingress
echo "setting tc"
tc filter add dev ${IF} parent ffff: \
protocol ip prio 1 \
u32 match ip dport ${PORT} 0xffff \
police rate ${LIMIT} burst $BURST drop \
flowid :1
tc filter add dev ${IF} parent ffff: \
protocol ip prio 1 \
u32 match ip sport ${PORT} 0xffff \
police rate ${LIMIT} burst $BURST drop \
flowid :1
我已经调整了相当长一段时间,尝试了各种不同的限制和突发值 - wgetting chozabu.net/testfile (12mb)
非常欢迎任何建议!
答案1
我不太确定您正在使用的 wlan 接口,但我猜您缺少虚拟接口,该接口应该将流量从 ethX 重定向,或者在您的情况下将 wlan3s0 重定向到 ifb,后者控制传入数据包
所以,类似于
modprobe ifb numifbs=1
ip link set dev ifb0 up
tc filter add dev wlp3s0 parent ffff: protocol ip u32 match u32 0 0 action mirred egress redirect dev ifb0
tc qdisc add dev $VIRTUAL root handle 2: htb
tc filter add dev $VIRTUAL protocol ip parent 2: prio 1 u32 match ip sport ${PORT} 0xffff police rate ${LIMIT} burst $BURST drop \
flowid :1
我创建了一个 bash 脚本,它允许您过滤特定 IP 地址(或网络)上传入和/或传出流量的带宽
https://gist.github.com/ole1986/d9d6be5218affd41796610a35e3b069c
Usage: ./traffic-control.sh [-r|--remove] [-i|--incoming] [-o|--outgoing] <IP>
Arguments:
-r|--remove : removes all traffic control being set
-i|--incoming : limit the bandwidth only for incoming packetes
-o|--outgoing : limit the bandwidth only for outgoing packetes
<IP> : the ip address to limit the traffic for