How to install and use vnstat (Network Traffic Monitor) in linux

Photo of author

By rasho

vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won’t actually be sniffing any traffic and also ensures light use of system resources.
In this article we will show you how to install and use vnStat (Network Traffic Monitor) on RHEL/CentOS linux distribution.

vnstat features

  • quick and simple to install and get running
  • gathered statistics persists through system reboots
  • can monitor multiple interfaces at the same time
  • several output options
    • summary, hourly, daily, monthly, weekly, top 10 days
    • optional png image output (using libgd)
  • months can be configured to follow billing period
  • light, minimal resource usage
  • same low cpu usage regardless of traffic
  • can be used without root permissions

Install VnStat on RHEL/CentOS 6.x/7.x Linux

To start, you will need to enable the EPEL repositories for your version of Linux. To enable the EPEL repositories in CentOS/RHEL 6.x enter following command:

$wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
$rpm -ivh epel-release-latest-6.noarch

To enable the EPEL repositories in CentOS/RHEL 7.x enter following command:

$ yum -y install epel-release

Next, you can install VnStat as normal through yum.

$ yum -y install vnstat

Once installed, the default configuration will work for most people. The default will run on the eth0 interface. If you need to change the interfaces, you will need to edit two files. It’s self explanatory. Change the occurrences of eth0 to eth1 (or your choice of interface).

nano /etc/sysconfig/vnstat
nano /etc/vnstat.conf

Next, we need to create the database where the data will be collected and stored. The command may generate an error. If it does, that’s fine. It is because the new file is created with ownership of the logged in user. We will fix this by running a chown on the file before starting the service.

$ vnstat -u -i eth0
$ chown vnstat:vnstat /var/lib/vnstat/eth0

That’s it. You’re ready to start the service and start collecting data.

$ service vnstat start
$ chkconfig vnstat on

[ads]

How to use VnStat

Using VnStat command line utility you can view statistics on bandwidth on per day, per month and per hour basis. It also provides option to show statistics in real-time.

Show Statistics for a day
To see daily stats, enter:

$ vnstat -d
VnStat daily
VnStat daily

Show Statistics for a Month

To see monthly network stats, enter:

$ vnstat -m
VnStat month
VnStat month

Show Statistics for a weekly

To see weekly network stats, enter:

$ vnstat -w
weekly network stats
weekly network stats

Show Statistics for a Hour

To see hourly network stats, enter:

$ vnstat -h
Show Statistics for a Hour
Show Statistics for a Hour

Show top 10 network stats

To see top 10 network, stats:

$ vnstat -t
top 10 network stats
top 10 network stats

Show Statistics in Real Time

To see transfer rate in real time, enter:

$ vnstat -l

That is all. Lots more information about the usage and options can be found out in the vnStat man page.

1 thought on “How to install and use vnstat (Network Traffic Monitor) in linux”

Leave a Comment