gpt4 book ai didi

ubuntu - linux tc 命令不限制下载速度

转载 作者:行者123 更新时间:2023-12-04 19:06:52 28 4
gpt4 key购买 nike

我编写了一个脚本,可以让我通过 ts 限制我的带宽。 Ubuntu 18.04.5 LTS 上的工具。
问题是,即使上传速度正确限制在我在脚本上设置的限制,下载速度也不会被限制,我不明白为什么。
链接在这里

#!/bin/bash  
# Full path to tc binary

TC=$(which tc)

interface=ens33
interface_speed=100mbit
ip=192.168.42.130 # The IP address bound to the interface

download_limit=512kbit
upload_limit=1mbit

# Filter options for limiting the intended interface.
FILTER="$TC filter add dev $interface protocol ip parent 1: prio 1 u32"

function start_tc {
tc qdisc show dev $interface | grep -q "qdisc pfifo_fast 0"
tc qdisc del dev $interface root; sleep 1
#[ "$?" -gt "0" ] && tc qdisc del dev $interface root; sleep 1

# start the tc configuration
$TC qdisc add dev $interface root handle 1: htb default 30
$TC class add dev $interface parent 1: classid 1:1 htb rate $interface_speed burst 15k

$TC class add dev $interface parent 1:1 classid 1:10 htb rate $download_limit burst 15k
$TC class add dev $interface parent 1:1 classid 1:20 htb rate $upload_limit burst 15k

$TC qdisc add dev $interface parent 1:10 handle 10: sfq perturb 10
$TC qdisc add dev $interface parent 1:20 handle 20: sfq perturb 10

# Apply the filter rules

# Catch-all IP rules, which will set global limit on the server
# for all IP addresses on the server.
$FILTER match ip dst 0.0.0.0/0 flowid 1:10
$FILTER match ip src 0.0.0.0/0 flowid 1:20

# If you want to limit the upload/download limit based on specific IP address
# you can comment the above catch-all filter and uncomment these:
#
# $FILTER match ip dst $ip/32 flowid 1:10
# $FILTER match ip src $ip/32 flowid 1:20
}

function show_status {
$TC -s qdisc ls dev $interface
}
#
# Display help
#
function display_help {
echo "Usage: tc [OPTION]"
echo -e "\tstart - Apply the tc limit"
echo -e "\tstatus - Show status"
}

# Start
if [ -z "$1" ]; then
display_help
elif [ "$1" == "start" ]; then
start_tc
elif [ "$1" == "status" ]; then
show_status
fi

最佳答案

一个可能的解决方案可能是

$TC qdisc del dev $IF root
echo "== DELETE DONE =="

$TC qdisc add dev $IF root handle 1:0 htb default 10

$TC class add dev $IF parent 1:0 classid 1:1 htb rate $LIMIT

$TC class add dev $IF parent 1:1 classid 1:10 htb rate 5mbit ceil $LIMIT_1
$TC class add dev $IF parent 1:1 classid 1:30 htb rate 5mbit ceil $LIMIT_2

$TC filter add dev $IF protocol ip parent 1:0 prio 2 u32 match ip dst x.x.x.x flowid 1:10
$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32 match ip dst x.x.x.x flowid 1:30

echo "== SHAPING DONE =="
其中 $IF 是您要使用的网络接口(interface), $TC tc 命令的路径(确保在脚本顶部设置 TC=/sbin/tc 看起来,在您的代码中,没有路径。
PS x.x.x.x 是您要绑定(bind)带宽限制的 IP 地址

关于ubuntu - linux tc 命令不限制下载速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66785698/

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