Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 3 down vote accepted

The iptables quota module can be quite useful, too.

share|improve this answer
add comment

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  0.0.0.0/0            192.168.122.0/24    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 –  haw3d Jul 30 '10 at 16:55
add comment

Your Answer

 
discard

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.