I have a computer that is configured as a router with two NIC's, one is connected to Internet, the other is connected to the local network switch.

I know that I can get the current throughput of NIC's by creating a script that reads files in the:/sys/class/net/[dev]/statistics directory.

But is it possible to get the throughput of every single client on the network, so I can see how much internet bandwidth each client is using?

  • It will probably be easier to track that at the perimeter router/firewall level. You can probably set up some reporting per IP address. In the case you can't, you can use a monitoring service to send reports of NIC usage and trend that at a monitoring server (something Nagios would work). – prateek61 Jun 28 '16 at 2:38

To have the usage per IP address, You can create an iptable rule for each IP address in the FORWARD chain and track iptables statistics counters.

Taking it from Network Statistics with iptables and rrdtool

iptables -N stats  
iptables -A stats -s -o $WAN -j RETURN
iptables -A stats -d -i $WAN -j RETURN  
iptables -A stats-s -o $WAN -j RETURN 
iptables -A stats -d -i $WAN -j RETURN 
iptables -A stats -o $WAN -j RETURN 
iptables -A stats -i $WAN -j RETURN 
iptables -A FORWARD -j stats

In fact I ran in the past an ISP, and they tracked the bandwidth usage of a couple of thousand customers with iptables using this method before I implemented Netflow accounting drinking the data from Cisco routers.

  • That was very little dynamical? With this method I have to create a new IPTables rule for every new client that connect to the network. – BufferOverflow Jun 29 '16 at 13:46
  • 1
    As far as I remember in the ISP it was done in perl. Networks do not change so often - you just do it to the whole range, not for every new PC. It worked for them for a few years. – Rui F Ribeiro Jun 29 '16 at 13:48
  • 1
    Yeah, of course. What was I thinking of. – BufferOverflow Jun 29 '16 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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