gpt4 book ai didi

trafficshaping - Linux 中的 TC(流量控制)

转载 作者:行者123 更新时间:2023-12-05 04:10:49 30 4
gpt4 key购买 nike

我正在使用此页面中的代码来限制我的上传和下载带宽。

https://help.atmail.com/hc/en-us/articles/201566464-Throttling-Bandwidth-using-Traffic-Controller-for-Linux

代码:

TC=/sbin/tc

IF=eth0 # Interface

DNLD=1mbit # DOWNLOAD Limit

UPLD=1mbit # UPLOAD Limit

IP=0.0.0.0 # Host IP

U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u0"

start() {

$TC qdisc add dev $IF root handle 1: htb default 30
$TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD
$TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD
$U32 match ip dst $IP/0 flowid 1:1
$U32 match ip src $IP/0 flowid 1:2

}

stop() {

$TC qdisc del dev $IF root

}

restart() {

stop
sleep 1
start

}

show() {

$TC -s qdisc ls dev $IF

}

case "$1" in

start)

echo -n "Starting bandwidth shaping: "
start
echo "done"
;;

stop)

echo -n "Stopping bandwidth shaping: "
stop
echo "done"
;;

restart)

echo -n "Restarting bandwidth shaping: "
restart
echo "done"
;;

show)

echo "Bandwidth shaping status for $IF:"
show
echo ""
;;

*)

pwd=$(pwd)
echo "Usage: tc.bash {start|stop|restart|show}"
;;

esac

我更改了“IP=0.0.0.0”和“$IP/0”,因此它可以在任何机器(具有所有 IP)上使用。

当我使用类似以下网站进行测试时:http://www.speedtest.net/看效果,我的上传是1mbps(我在文件里配置的)但是下载不听我的命令。下载带宽远高于配置值。

默认值:

eth0 的带宽整形状态:

qdisc pfifo_fast 0: root refcnt 2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 108 bytes 2 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0

过滤后的值:

eth0 的带宽整形状态:

qdisc htb 1: root refcnt 2 r2q 10 default 30 direct_packets_stat 0 direct_qlen 1000
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0

有人知道可能是什么问题吗?

最佳答案

您是否使用了此配置中的代码:

TC=/sbin/tc

IF=eth0 # Interface

DNLD=1mbit # DOWNLOAD Limit

UPLD=1mbit # UPLOAD Limit

IP=0.0.0.0 # Host IP

U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u0"

start() {

$TC qdisc add dev $IF root handle 1: htb default 30
$TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD
$TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD
$U32 match ip dst $IP/0 flowid 1:1
$U32 match ip src $IP/0 flowid 1:2

}

stop() {

$TC qdisc del dev $IF root

}

restart() {

stop
sleep 1
start

}

show() {

$TC -s qdisc ls dev $IF

}

case "$1" in

start)

echo -n "Starting bandwidth shaping: "
start
echo "done"
;;

stop)

echo -n "Stopping bandwidth shaping: "
stop
echo "done"
;;

restart)

echo -n "Restarting bandwidth shaping: "
restart
echo "done"
;;

show)

echo "Bandwidth shaping status for $IF:"
show
echo ""
;;

*)

pwd=$(pwd)
echo "Usage: tc.bash {start|stop|restart|show}"
;;

esac

关于trafficshaping - Linux 中的 TC(流量控制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43894432/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com