≡ Menu

Keeping a Log Of Daily Network Traffic for ADSL or Dedicated Remote Linux Server

Almost a year ago, I wrote about Linux MRTG configuration how-to. However, some user seems to confused with MRTG, most users would like to know – how much traffic actually generated by ADSL/Cable service provider on daily and monthly basis.

MRTG is for network monitoring and it can be use to see how much traffic your server or ADSL router actually generated, however it will not tell you how much megabytes or gigabytes the daily traffic was. For all such home user and people having dedicated single Linux box hosted somewhere remote at IDC/ISP there is a tool called vnStat:

  • It is a console-base network traffic monitor for Linux (perfect tool for remote Linux box hosted at ISP)
  • It keeps a log of daily and monthly network traffic for the selected network interface(s).
  • It collects all data from /proc file system it means normal user can monitor traffic (no need to run vnstat as a root user)
  • Easy to setup & configure
  • Ease of use

Step # 1: Install vnstat

Debian / Ubuntu Linux user can install vnstat using apt-get command, enter:

# apt-get install vnstat 

Step # 2: Enable vnstat

Once installed, you need to create a database with the following command:

# vnstat -u -i eth0


  • -u :forces a database update for interface or creates the database if it doesn’t exist
  • -i eth0 : use to specify interface

Please note that it will start to collect data via cronjob:

0-55/5 * * * *   root    /usr/bin/vnstat -u

You do not have to install cronjob yourself; it should be automatically configure by apt-get.

Step # 3 View statistics

Display default traffic statistics

$ vnstat

Display daily traffic statistics

$ vnstat -d

Display monthly traffic statistics:

$ vnstat -m

Display all time top10 traffic days:

$ vnstat -t 

Try help option to get all query options:

$ vnstat --help

Read man page of vnstat for complete options and more information and download vnstat here

Share this on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 15 comments… add one }
  • rabba December 13, 2005, 12:47 pm

    was looking for something like this for ages…. it is better than mrtg and perfect for home ADSL user

  • Anonymous January 31, 2006, 2:01 am

    Also check out bmon. It doesn’t exactly log your traffic to a file, but it does do live graphical/textual representation of it for monitoring. Great for CABLE/DSL boxes.

  • Erik Bussink June 6, 2007, 12:21 am

    I recomment to look at the vnstat-php-frontend add on. it’s a php interface showing the stats gathered by vnstat.


  • soraver May 6, 2008, 12:54 pm

    very nice tool, thanks :)

  • Redptc May 7, 2008, 10:28 pm

    Just perfect so far! I haven’t accumulated a lot of stats yet but it seems to be working well!

    It is also a real bonus that it operates in the ‘background’, unobtrusive but efficient.

    Thanks for the effort and thanks for an excellent tool.

  • Omid March 6, 2009, 10:03 am

    great article sir. thank you.

  • vinnie March 29, 2009, 6:49 am

    This tool is really nice …It worked for me on my Ubuntu 8.10 distribution ,when coming to F10 its just didnt ….I’ve done the same config…Seems ” Not enough data available yet ” even after 3 days …

    But this is amazing tool with very less config …………

    Thanks for the Help

    • nixCraft March 29, 2009, 7:48 am

      You need to instal cron job and needs some traffic to get data.

  • Mehran Khajavi April 28, 2009, 12:45 pm

    very useful think
    thanks alot

  • pixeldoc November 18, 2009, 7:26 pm

    Nice tool and a very useful blog!

    @vinnie: You have to add cronjob yourself on Ubuntu 8.10.

  • airtonix February 6, 2010, 2:14 pm

    any way to whitelist certain destinatons?

    australian ISPs enforce a monthly bandwidth quota on consumers. Most good australians ISP also provide larges amounts of locally mirrored data that don’t count towards that monthly quota.

    I’d like to white list some IP addresses in order to obtain a report relevant to usage affecting the monthly quota my isp provides me.

    • nixCraft February 6, 2010, 2:36 pm

      Not possible as vnstat reads raw kernel counters and stores them in /var/lib/vnstat/eth0. Try contacting its author and see if he can come with some solution.


  • Vireak March 8, 2010, 8:33 am

    Yeah! I saw other code at above are good, but I want to see script for manage over user in the company and conditions to user

  • Zhabba December 6, 2010, 8:57 pm

    Thanks, very useful tool.
    P.S. On Fedora 14 you need uncomment line in /etc/cron.d/vnstat

  • zeo9 June 18, 2012, 2:44 pm

    Thanks for the guide. I know it’s a long time after but the install or db creation did not seem to add a cron anywhere. Lucky you included it in your article. I’m going to checkout the frontend posted by Erik: http://www.sqweek.com/sqweek/index.php?p=1

Leave a Comment

   Tagged with: , , , , , , , , , , , , , , , , , , , , ,