I'm having trouble adding the script code for you here, it is available via this gist - https://gist.github.com/akrasic/7242498#file-limit-tc-sh
The script is using TC and Hierarchical Token Bucket (HTB) to define the rules and lastly the filters that would act as a catch-all rule.
You would need to modify the interface
var if it's different than eth0
˙and the interface_speed
.
Save the script on your server, and start it via:
ḃash limit-tc.sh start
To stop:
bash limit-tc.sh stop
View status: bash limit.tc status
Status output would look something like this:
qdisc htb 1: root refcnt 2 r2q 10 default 30 direct_packets_stat 1
Sent 535666 bytes 6461 pkt (dropped 172, overlimits 7641 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc sfq 10: parent 1:10 limit 127p quantum 1514b perturb 10sec
Sent 535624 bytes 6424 pkt (dropped 172, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc sfq 20: parent 1:20 limit 127p quantum 1514b perturb 10sec
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0