Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

The iptables quota module can be quite useful, too.

share|improve this answer

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:

 iptables -A FORWARD -s <ip>
 iptables -A FORWARD -d <ip>

And then you can get the results with iptables -nv -L FOWARD that will return something like this:

# iptables -nvL FORWARD
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      virbr0      state RELATED,ESTABLISHED

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 use tc to throttle their bandwidth, or anything else.

share|improve this answer
thank you, its very useful – hamedsh Jul 30 '10 at 16:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.