Build bandwidth manager on linux with TC, HTB, IFB
Previously we already build Bandwidth management with connection marking by iptables, you can read on Build bandwidth manager on linux with TC, HTB and iptables mark connection. the different is we not marking connection, but with IFB module we create dummy interface whose mirred from originate network interface, so we can match it by port, source ip, or others, this case we show by ip address matcher
topologi internet --- (eth0, 192.168.1.1/24) linux gateway (eth1, 192.168.80.1/20) --- client
hope this article help you
Step by step
- set up your linux internet gateway
- setup TC with IFB
1. set up your linux internet gateway
you can follow previous article at Build router internet gateway on ubuntu linux
2. setup TC
execute this to create parent upload, with max upload 10Mbps #---upload limit parent--- "/sbin/tc qdisc del dev eth1 handle ffff: ingress" "/sbin/tc qdisc del dev ifb0 root" "/sbin/tc qdisc add dev eth1 handle ffff: ingress" "/sbin/tc filter add dev eth1 parent ffff: protocol ip u32 match u32 0 0 action mirred egress redirect dev ifb0" "/sbin/tc qdisc add dev ifb0 root handle 1: htb default 255 r2q 10" "/sbin/tc class add dev ifb0 parent 1: classid 1:10 htb rate 10240Kbit" #---upload limit for 192.168.80.2 client, with max upload bandwidth 1Mbps, and lower bandwidth 25Kbit--- "/sbin/tc class add dev ifb0 parent 1:10 classid 1:102 htb rate 25Kbit ceil 1024Kbit prio 5" "/sbin/tc qdisc add dev ifb0 parent 1:102 handle 102: sfq perturb 10" "/sbin/tc filter add dev ifb0 parent 1: protocol ip prio 100 u32 match ip src 192.168.80.2 flowid 1:102" #---upload limit for 192.168.80.3 client, with max upload bandwidth 2Mbps, and lower bandwidth 25Kbit--- "/sbin/tc class add dev ifb0 parent 1:10 classid 1:103 htb rate 25Kbit ceil 2048Kbit prio 5" "/sbin/tc qdisc add dev ifb0 parent 1:103 handle 103: sfq perturb 10" "/sbin/tc filter add dev ifb0 parent 1: protocol ip prio 100 u32 match ip src 192.168.80.3 flowid 1:103"
execute this to create parent udownload #---upload limit parent, with max download 100Mbps--- "/sbin/tc qdisc del dev eth1 root" "/sbin/tc qdisc add dev eth1 root handle 1: htb default 255 r2q 10" "/sbin/tc class add dev eth1 parent 1: classid 1:20 htb rate 102400Kbit" #---upload limit for 192.168.80.2 client, with max download bandwidth 3Mbps, and lower bandwidth 256Kbit--- "/sbin/tc class add dev eth1 parent 1:20 classid 1:102 htb rate 256Kbit ceil 3072Kbit prio 5" "/sbin/tc qdisc add dev eth1 parent 1:102 handle 102: sfq perturb 10" "/sbin/tc filter add dev eth1 parent 1: protocol ip prio 100 u32 match ip dst 192.168.80.2 flowid 1:102" #---upload limit for 192.168.80.3 client, with max download bandwidth 5Mbps, and lower bandwidth 256Kbit--- "/sbin/tc class add dev eth1 parent 1:20 classid 1:103 htb rate 256Kbit ceil 5120Kbit prio 5" "/sbin/tc qdisc add dev eth1 parent 1:103 handle 103: sfq perturb 10" "/sbin/tc filter add dev eth1 parent 1: protocol ip prio 100 u32 match ip dst 192.168.80.3 flowid 1:103"
thats it, you can test it with external tools like speedtest.net
i dont create the image, i got from icon-library.com