WireGuard:限制下載和上傳頻寬

WireGuard:限制下載和上傳頻寬

我試圖將每個wireguard 對等點的下載和上傳速度限制為512kbit。

問題是我的以下命令,只限制下載頻寬對等體且不限制上傳頻寬。任何幫助,將不勝感激。

tc 規則,例如 ip 10.7.0.2 和 iptables 標記 12 的對等點:

tc qdisc add dev eth0 root handle 1: htb
tc qdisc add dev wg0 root handle 1: htb

tc class add dev eth0 parent 1:1 classid 1:12 htb rate 512kbit ceil 512kbit
tc qdisc add dev eth0 parent 1:12 sfq perturb 10
tc filter add dev eth0 protocol ip parent 1: prio 1 handle 12 fw flowid 1:12

tc class add dev wg0 parent 1:1 classid 1:12 htb rate 512kbit ceil 512kbit
tc qdisc add dev wg0 parent 1:12 sfq perturb 10
tc filter add dev wg0 protocol ip parent 1: prio 1 handle 12 fw flowid 1:12

對於 iptables,我用數字 12 標記對等點,因此 tc 確實對其進行了限制:

iptables -I FORWARD -s 10.7.0.2 -j MARK --set-mark 12
iptables -I FORWARD -d 10.7.0.2 -j MARK --set-mark 12 

謝謝!

答案1

使用此程式碼修復了問題,來自:https://stackoverflow.com/a/65248666/3411911

export IF_INET=eth0
export LIMIT=300kbit

tc qdisc add dev ${IF_INET} ingress

tc filter add dev ${IF_INET} protocol ip ingress prio 2 u32 match ip dst 0.0.0.0/0 action police rate ${LIMIT} burst ${LIMIT}
tc filter add dev ${IF_INET} protocol ip ingress prio 2 u32 match ip src 0.0.0.0/0 action police rate ${LIMIT} burst ${LIMIT}

相關內容