Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

This question already has an answer here:

I'd like to monitor my network traffic outside the local network on my main computer (a gentoo linux desktop workstation), which goes through a 3g wifi router (a Huawei e5220); this is a wifi only device, I have to connect to it directly through wireless connection, and I can't install any monitoring system on it.

I have a 10gb per month limit, but to check it I've to go on my mobile operator website and browse through 5 pages, and the web interface of the Huawei doesn't show reliable statistics. Since sometimes I have file transfers within the local network (a notebook, my mobile phone), the statistics shown in conky through totalup/totaldown or even the ifconfig's RX/TX output are not correct, since I'd just like to have the sum of R&T traffic outside of
I know that the statistics will not be precise (using other devices that will connect to internet through the 3g router, I'll never know the exact amount of used traffic if not by going to my operator's website), but an approximate value would be enough.

I already checked out other questions about iptraf, ifstat, wireshark and other tools (I don't want a graphic monitoring tool, I just need a simple output text I can use with python/bash scripting), but none of them seems to answer to my situation.


EDIT: This is not a duplicate of Monitoring Bandwidth Across Multiple Systems in a Home Network: as explained I can't change the firmware of the router and it's a wireless only device, so I can't use another computer or wifi router to monitor the bandwidth.

share|improve this question

marked as duplicate by Kevin Panko, Tog, Ƭᴇcʜιᴇ007, random Feb 15 '14 at 5:46

This question was marked as an exact duplicate of an existing question.

Monitor for what ? Why do you want to monitor traffic outside your network, lots of trashy traffic out there most of which has little or nothing to do with your bandwidth. Many routers will monitor traffic. If you tried various tools, what features did they lack? – bodhi.zazen Jan 17 '14 at 21:12
Have you tried using libpcap directly? It is what wireshark and the likes use. You can try making a script that lists only packets with your default gateway address as destination. – Jake Jan 17 '14 at 21:23

If you create 2 rules that are place holder affect you can use:

These rules do nothing except allow for the numbers to be collected. Make sure these are the first rules in there chains.

 iptables -I 1 INPUT -i eth0
 iptables -I 1 OUTPUT -i eth0

The collected data maybe viewed this way.

 iptables -L INPUT 1 -v -n -x
 iptables -L OUTPUT 1 -v -n -x

after getting the data you can zero the counters with this:

  iptables --zero    -Z [chain [rulenum]]  Zero counters in chain or all chains

If you want something more detailed I could give you some ipset rules that could count bytes per source and destination IP.

share|improve this answer
Sorry for this late answer. With iptables I can actually get what vnstat (and, partially, ifconfig) does, monitoring the whole wireless traffic; if you can help me with the ipset configuration I'll be grateful, since I tried to find some howto's but unfortunally I never really understood how network and iptables exactly work. – musicamante May 18 '14 at 18:10

Not the answer you're looking for? Browse other questions tagged .