更新 xs.sh
This commit is contained in:
parent
a318f5b996
commit
5ea5e89773
26
xs.sh
26
xs.sh
@ -5,7 +5,7 @@ INTERFACE="eno1"
|
||||
LIMIT_RATE="2mbit"
|
||||
|
||||
add_limit() {
|
||||
echo "Applying new bandwidth limit..."
|
||||
echo "Applying bandwidth limit for ports 8337 and 8338..."
|
||||
|
||||
# 加载 ifb 模块并确保 ifb0 存在且启用
|
||||
modprobe ifb 2>/dev/null
|
||||
@ -17,18 +17,21 @@ add_limit() {
|
||||
tc qdisc del dev ifb0 root 2>/dev/null || true
|
||||
|
||||
# 添加上行规则
|
||||
tc qdisc add dev "$INTERFACE" root handle 1: htb default 11
|
||||
tc class add dev "$INTERFACE" parent 1: classid 1:1 htb rate "$LIMIT_RATE"
|
||||
tc class add dev "$INTERFACE" parent 1:1 classid 1:11 htb rate "$LIMIT_RATE"
|
||||
tc filter add dev "$INTERFACE" protocol ip parent 1:0 prio 1 u32 match ip dport 8337 0xffff flowid 1:11
|
||||
tc filter add dev "$INTERFACE" protocol ip parent 1:0 prio 1 u32 match ip dport 8338 0xffff flowid 1:11
|
||||
tc qdisc add dev "$INTERFACE" root handle 1: htb
|
||||
tc class add dev "$INTERFACE" parent 1: classid 1:1 htb rate "$LIMIT_RATE" ceil "$LIMIT_RATE"
|
||||
tc filter add dev "$INTERFACE" protocol ip parent 1:0 prio 1 u32 match ip dport 8337 0xffff flowid 1:1
|
||||
tc filter add dev "$INTERFACE" protocol ip parent 1:0 prio 1 u32 match ip dport 8338 0xffff flowid 1:1
|
||||
|
||||
# 添加下行规则
|
||||
tc qdisc add dev ifb0 root handle 1: htb default 11
|
||||
tc class add dev ifb0 parent 1: classid 1:1 htb rate "$LIMIT_RATE"
|
||||
tc class add dev ifb0 parent 1:1 classid 1:11 htb rate "$LIMIT_RATE"
|
||||
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip sport 8337 0xffff flowid 1:11
|
||||
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip sport 8338 0xffff flowid 1:11
|
||||
tc qdisc add dev ifb0 root handle 1: htb
|
||||
tc class add dev ifb0 parent 1: classid 1:1 htb rate "$LIMIT_RATE" ceil "$LIMIT_RATE"
|
||||
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip sport 8337 0xffff flowid 1:1
|
||||
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip sport 8338 0xffff flowid 1:1
|
||||
|
||||
# 将 ingress 流量重定向到 ifb0
|
||||
tc qdisc add dev "$INTERFACE" ingress
|
||||
tc filter add dev "$INTERFACE" parent ffff: protocol ip prio 1 u32 match ip sport 8337 0xffff action mirred egress redirect dev ifb0
|
||||
tc filter add dev "$INTERFACE" parent ffff: protocol ip prio 1 u32 match ip sport 8338 0xffff action mirred egress redirect dev ifb0
|
||||
|
||||
echo "Bandwidth limit applied successfully."
|
||||
}
|
||||
@ -36,6 +39,7 @@ add_limit() {
|
||||
delete_limit() {
|
||||
echo "Removing bandwidth limit..."
|
||||
tc qdisc del dev "$INTERFACE" root 2>/dev/null || true
|
||||
tc qdisc del dev "$INTERFACE" ingress 2>/dev/null || true
|
||||
tc qdisc del dev ifb0 root 2>/dev/null || true
|
||||
ip link set ifb0 down 2>/dev/null || true
|
||||
echo "Bandwidth limit removed successfully."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user