Home » Questions » Computers [ Ask a new question ]

How can I calculate how much traffic goes through my router?

How can I calculate how much traffic goes through my router?

As I have more internet than I can use myself and I have free router I don't use I was thinking about making a free hotspot for the neighbors. Unfortunately, my traffic is limited though so I'd like to have some limits for its day usage. I will install dd-wrt or openwrt on the router to do that but last time I was trying to calculate traffic usage under Linux I had to write my own ulog filter for netfilter and I'd like to avoid doing so now. So is there a product I can use to achieve my goals i.e. break all connections for a day when limit is hit (or shape them down to 32kbps)?

Asked by: Guest | Views: 97
Total answers/comments: 2
Guest [Entry]

"Looks like with modern iptables limiting traffic is rather easy task.

Meet module quota:

iptables -A OUTPUT -p tcp --dport 80 -m quota --quota 1024 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j DROP

This will accept 1K of data and then drop all the connections :) --quota continuously decrementing the counter and when it hits 0 rule does not match any more, so the next one kicks in and block everything.

You can even see how much traffic is left

# iptables -L OUTPUT -v

Chain OUTPUT (policy ACCEPT 3640 packets, 1753K bytes)
pkts bytes target prot opt in out source destination
1 40 ACCEPT tcp -- any any anywhere anywhere tcp dpt:http quota: 984 bytes
0 0 DROP tcp -- any any anywhere anywhere tcp dpt:http

and after a while

# iptables -L OUTPUT -v

Chain OUTPUT (policy ACCEPT 3814 packets, 1773K bytes)
pkts bytes target prot opt in out source destination
8 996 ACCEPT tcp -- any any anywhere anywhere tcp dpt:http quota: 0 bytes
9 504 DROP tcp -- any any anywhere anywhere tcp dpt:http

Looks like if I can install this module on OpenWRT limiting the traffic would be an easy task."
Guest [Entry]

"To shape down the traffic, iptables would work on one of the two WRT installations you are considering.

Here is an openwrt forum thread reference for ideas -- Traffic shaping QOS howto;
Two more links."