Tuesday, 13 November 2012

Throttling traffic via iptables

Useful link answer to: Throttle Traffic via iptables question

Note from Graham Hargreaves (prob based on someone else) ...

Not very accurate but definitely restricts the flow.
Change modemif variable to be the interface you need to throttle.
The example below never allowed a download to go above 130kbs and set to ambit it never went above 3Mbs (Probably needs some more testing)

To turn on:


iptables -t mangle -A POSTROUTING -o $modemif -p tcp -m tos --tos Minimize-Delay -j CLASSIFY --set-class 1:10
iptables -t mangle -A POSTROUTING -o $modemif -p tcp --dport 80 -j CLASSIFY --set-class 1:10
iptables -t mangle -A POSTROUTING -o $modemif -p tcp --dport 443 -j CLASSIFY --set-class 1:10

tc qdisc add dev $modemif root handle 1: htb default 12
tc class add dev $modemif parent 1:1 classid 1:12 htb rate 50kbit ceil 50kbit

To turn the above off simply run:

tc qdisc del dev eth0 root

No comments: