14

Is there an easy way to limit user bandwidth usage to say 10kpbs? Other users should not be affected. The best I've found is tc, but it seems way too complicated to do such a simple thing.

0

1 Answer 1

8

tc is the correct answer to your configuration needs.
tc may seem complicated because it manages classfull (and less) queuing disciples which gives it unlimited flexibility and layers of shaping and filtering.
This however is not the case. As tc utilizes the built in (or modular) queuing disciples in the kernel it the simplest/best way of limiting bandwidth on a per user basis.
Here is a sample set-up, I left it in Mbit format but you can change the rate measure to kbps.

tc qdisc add dev eth0 root handle 1:0 htb
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 1Mbit ceil 1Mbit prio 1

For you iptables rule just change --uid-owner to the uid of the user you wish to limit, documentation says you can use the users name instead of UID, have not tested that.

iptables -t mangle -A POSTROUTING -o eth0 -p tcp -m owner --uid-owner 1000 -j CLASSIFY --set-class 1:1

FYI even though you do not need an HTB I would recommend it based on the available options and what speed you are limiting to.

2
  • How do we do this for all users of openvpn on tun0?
    – PouJa
    May 22, 2023 at 22:30
  • I dont want to manage per user, I want to limit all users to 5Mbit
    – PouJa
    May 22, 2023 at 22:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .