Skip to content

Instantly share code, notes, and snippets.

@ddrown
Created July 22, 2014 18:24
Show Gist options
  • Save ddrown/20c2969731367cfbf046 to your computer and use it in GitHub Desktop.
Save ddrown/20c2969731367cfbf046 to your computer and use it in GitHub Desktop.
Per-user rate limiting
#!/bin/sh
iptables -t mangle -A OUTPUT -m owner --uid-owner slowuser -j CLASSIFY --set-class 1:11
tc qdisc add dev em1 root handle 1:0 htb default 99
tc class add dev em1 parent 1:0 classid 1:1 htb rate 1000Mbit ceil 1000Mbit
tc class add dev em1 parent 1:1 classid 1:11 htb rate 1Mbit ceil 1Mbit prio 2
tc qdisc add dev em1 parent 1:11 handle 10: sfq perturb 10
# normal user iperf: 0.0-10.1 sec 8.25 MBytes 6.83 Mbits/sec
# slowuser iperf: 0.0-11.8 sec 1.75 MBytes 1.24 Mbits/sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment