I'm writing software for bandwidth management in Linux. I use TC for bandwidth shaping, and it worked fine. I want to limit user bandwidth for a period of time. For example:
- For user 1, 100MB in a week
What is the best way to do it?
I'm writing software for bandwidth management in Linux. I use TC for bandwidth shaping, and it worked fine. I want to limit user bandwidth for a period of time. For example:
What is the best way to do it?
You can add an iptables rule for each IP and use it to count the traffic that passed through the rule. Just add 2 rules for each IP:
And then you can get the results with
iptables -nv -L FOWARD
that will return something like this:This one is zero but the
bytes
column will give you what you want I swear :)After that all you need is a
cron
job to save those values, and to check if they are over the alloted bytes that week, then change the rules to block the traffic or usetc
to throttle their bandwidth, or anything else.The iptables quota module can be quite useful, too.