┌─[mybox]─[/etc/htb]
└──╼ cat enp5s0
# eth0 device
DEFAULT=99
R2Q=100
┌─[mybox]─[/etc/htb]
└──╼ cat enp5s0-2.root
# root class containing total bandwidth
RATE=20Mbit
CEIL=20Mbit
BURST=1Mbit
┌─[mybox]─[/etc/htb]
└──╼ cat enp5s0-2:10.www
# class for WWW traffic
RATE=128Kbit
CEIL=20Mbit
PRIO=1
RULE=*:80,
RULE=*:443,
RULE=*:8008,
RULE=*:8080,
RULE=*:80
RULE=*:443
RULE=*:8008
RULE=*:8080
LEAF=sfq
┌─[mybox]─[/etc/htb]
└──╼ cat enp5s0-2:99.dfl
# class for all other traffic
RATE=128Kbit
CEIL=20Mbit
PRIO=7
LEAF=sfq
На выходе получается это:
└──╼ htb.init compile;/etc/init.d/htbinit reload;/etc/init.d/htbinit restart
/sbin/tc qdisc del dev enp5s0 root
/sbin/tc qdisc add dev enp5s0 root handle 1 htb default 99 r2q 100
/sbin/tc class add dev enp5s0 parent 1: classid 1:2 htb rate 20Mbit ceil 20Mbit burst 1Mbit
/sbin/tc class add dev enp5s0 parent 1:2 classid 1:10 htb rate 128Kbit ceil 20Mbit prio 1
/sbin/tc qdisc add dev enp5s0 parent 1:10 handle 10 sfq perturb 10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip sport 80 0xffff classid 1:10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip sport 443 0xffff classid 1:10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip sport 8008 0xffff classid 1:10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip sport 8080 0xffff classid 1:10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip dport 80 0xffff classid 1:10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip dport 443 0xffff classid 1:10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip dport 8008 0xffff classid 1:10
/sbin/tc filter add dev enp5s0 parent 1:0 protocol ip prio 100 u32 match ip dport 8080 0xffff classid 1:10
/sbin/tc class add dev enp5s0 parent 1:2 classid 1:99 htb rate 128Kbit ceil 20Mbit prio 7
/sbin/tc qdisc add dev enp5s0 parent 1:99 handle 99 sfq perturb 10
Теперь мне нужно классифицировать трафик из iptables:
$IPTABLES -t mangle -A POSTROUTING -p TCP --dport 80 -j CLASSIFY --set-class 1:10
$IPTABLES -t mangle -A POSTROUTING -p TCP --dport 443 -j CLASSIFY --set-class 1:10
┌─[mybox]─[/home/user]
└──╼ tc -s class show dev enp5s0
class htb 1:99 parent 1:2 leaf 99: prio 7 rate 128000bit ceil 20000Kbit burst 1600b cburst 1600b
Sent 190751 bytes 2201 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
lended: 1890 borrowed: 311 giants: 0
tokens: -50980 ctokens: 9325
class htb 1:10 parent 1:2 leaf 10: prio 1 rate 128000bit ceil 20000Kbit burst 1600b cburst 1600b
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
lended: 0 borrowed: 0 giants: 0
tokens: 1562500 ctokens: 10000
class htb 1:2 root rate 20000Kbit ceil 20000Kbit burst 128Kb cburst 1600b
Sent 190751 bytes 2201 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
lended: 311 borrowed: 0 giants: 0
tokens: 818512 ctokens: 9325