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 the apt-get command/apt command, enter:

# apt-get install vnstat


# apt install vnstat

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 84.0 kB of archives.
After this operation, 259 kB of additional disk space will be used.
Get:1 stretch/main amd64 vnstat amd64 1.15-2 [84.0 kB]
Fetched 84.0 kB in 2s (39.8 kB/s)
Selecting previously unselected package vnstat.
(Reading database ... 115133 files and directories currently installed.)
Preparing to unpack .../vnstat_1.15-2_amd64.deb ...
Unpacking vnstat (1.15-2) ...
Setting up vnstat (1.15-2) ...
Created symlink /etc/systemd/system/ → /lib/systemd/system/vnstat.service.
Processing triggers for systemd (232-25+deb9u1) ...
Processing triggers for man-db ( ...

Fedora Linux user type the following dnf command:

# dnf install vnstat

CentOS/RHEL users type the following [nxicmd name=”yum”] after enabling epel repo on CentOS/RHEL 5.x/6.x or RHEL/CentOS 7.x:

# yum install vnstat

Sample outputs:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
Resolving Dependencies
--> Running transaction check
---> Package vnstat.x86_64 0:1.15-2.el7 will be installed
--> Processing Dependency: for package: vnstat-1.15-2.el7.x86_64
--> Running transaction check
---> Package gd.x86_64 0:2.0.35-26.el7 will be installed
--> Processing Dependency: for package: gd-2.0.35-26.el7.x86_64
--> Running transaction check
---> Package libXpm.x86_64 0:3.5.11-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
 Package            Arch               Version                    Repository        Size
 vnstat             x86_64             1.15-2.el7                 epel             125 k
Installing for dependencies:
 gd                 x86_64             2.0.35-26.el7              base             146 k
 libXpm             x86_64             3.5.11-3.el7               base              54 k
Transaction Summary
Install  1 Package (+2 Dependent packages)
Total download size: 325 k
Installed size: 982 k
Is this ok [y/d/N]: y
Downloading packages:
(1/3): gd-2.0.35-26.el7.x86_64.rpm                                | 146 kB  00:00:00     
(2/3): libXpm-3.5.11-3.el7.x86_64.rpm                             |  54 kB  00:00:02     
(3/3): vnstat-1.15-2.el7.x86_64.rpm                               | 125 kB  00:00:02     
Total                                                       143 kB/s | 325 kB  00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libXpm-3.5.11-3.el7.x86_64                                            1/3 
  Installing : gd-2.0.35-26.el7.x86_64                                               2/3 
  Installing : vnstat-1.15-2.el7.x86_64                                              3/3 
  Verifying  : vnstat-1.15-2.el7.x86_64                                              1/3 
  Verifying  : gd-2.0.35-26.el7.x86_64                                               2/3 
  Verifying  : libXpm-3.5.11-3.el7.x86_64                                            3/3 
  vnstat.x86_64 0:1.15-2.el7                                                             
Dependency Installed:
  gd.x86_64 0:2.0.35-26.el7                 libXpm.x86_64 0:3.5.11-3.el7                

Step # 2: Enable vnstat

Once installed, you need to create a database with the following commands. The latest version uses config file, you need to edit it as follows:
$ sudo vi /etc/vnstat.conf
Make sure you setup correct interface name:

# default interface
Interface "wlp4s0"

Save and close the file using vi/vim command. Once done start the vnstat server as follows:
$ sudo systemctl start vnstat

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

Sample outputs:

 vnStat 1.15 by Teemu Toivola <tst at iki dot fi>
         -q,  --query          query database
         -h,  --hours          show hours
         -d,  --days           show days
         -m,  --months         show months
         -w,  --weeks          show weeks
         -t,  --top10          show top 10 days
         -s,  --short          use short output
         -u,  --update         update database
         -i,  --iface          select interface (default: eth1)
         -?,  --help           short help
         -v,  --version        show version
         -tr, --traffic        calculate traffic
         -ru, --rateunit       swap configured rate unit
         -l,  --live           show transfer rate in real time

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 15 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
15 comments… add one
  • rabba Dec 13, 2005 @ 12:47

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

  • Anonymous Jan 31, 2006 @ 2:01

    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 Jun 6, 2007 @ 0:21

    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

    very nice tool, thanks 🙂

  • Redptc May 7, 2008 @ 22:28

    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 Mar 6, 2009 @ 10:03

    great article sir. thank you.

  • vinnie Mar 29, 2009 @ 6:49

    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 Mar 29, 2009 @ 7:48

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

  • Mehran Khajavi Apr 28, 2009 @ 12:45

    very useful think
    thanks alot

  • pixeldoc Nov 18, 2009 @ 19:26

    Nice tool and a very useful blog!

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

  • airtonix Feb 6, 2010 @ 14:14

    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 Feb 6, 2010 @ 14:36

      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 Mar 8, 2010 @ 8:33

    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 Dec 6, 2010 @ 20:57

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

  • zeo9 Jun 18, 2012 @ 14:44

    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:

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum