Skip to content
Related Articles

Related Articles

Improve Article
How to Install and Use vnstat Network Traffic Monitoring Tool in Linux?
  • Last Updated : 17 Mar, 2021

VnStat is a network utility that uses a command-line interface designed for Linux. Logs of the selected interface(s) of hourly, daily, and monthly network traffic are kept, although it is not a packet sniffer. The network interface statistics that are provided by the kernel as the information source is used by VnStat, which means vnStat will not actually sniff any traffic and also ensures light use of system resources. 

In this article, we will show you how to install, Run vnstat, and More options of vnstat under the Linux system with Debian/Ubuntu Linux.

Install Vnstat Network Monitoring Tool On Debian, Ubuntu

The following command will install Vnstat:

sudo apt-get install vnstat
Linux vnstat a Console Network Traffic Monitoring Tool

sudo apt-get install vnstat

Check Running vnstat:

Running vnstat can be quite confusing because You can face many errors. When you will type vnstat on your terminal for the first time then the following error will be shown:-



$ vnstat
Error: Unable to open database directory "/var/lib/vnstat": No such file or directory
The vnStat daemon should have created this directory when started.
Check that it is is configured and running. See also "man vnstatd".

We have to create a database with the interface we want to add by typing the following command:

/usr/bin/vnstat --add -i [interface name]
Linux vnstat a Console Network Traffic Monitoring Tool

it can be eth0 or wlan0 according to your requirement

But vnstat is still not running. So we have to start the daemon by running the following command and check after some time:

sudo /etc/init.d/vnstat start 

Linux vnstat a Console Network Traffic Monitoring Tool

This will be the following result:

Linux vnstat a Console Network Traffic Monitoring Tool

Sometimes you may find the following error:

Linux vnstat a Console Network Traffic Monitoring Tool

Now, we have to make vnstat daemon auto-start at boot by typing the following command:



sudo systemctl enable vnstat.service

Linux vnstat a Console Network Traffic Monitoring Tool

Unfortunately, vnstat log file is created as a root and not as any normal user. So we have to change its permissions to allow vnstat to write data to it using the following command:

sudo chown <owner_name> -R /var/lib/vnstat/*

More options of vnstat:

There are some options of vmstat that may be helpful on daily basis. They are as follows:

Displaying hours based traffic

/usr/bin/vnstat --hours

Linux vnstat a Console Network Traffic Monitoring Tool

Displaying days based traffic:

/usr/bin/vnstat --days

Linux vnstat a Console Network Traffic Monitoring Tool

Show months based traffic:

 /usr/bin/vnstat --months

Linux vnstat a Console Network Traffic Monitoring Tool

Calculate traffic:

/usr/bin/vnstat -tr

Linux vnstat a Console Network Traffic Monitoring Tool

Show transfer rate in real-time:

Linux vnstat a Console Network Traffic Monitoring Tool

Showing in online:

Linux vnstat a Console Network Traffic Monitoring Tool

For getting more info follow the manual by typing the following command:

man vnstat

Linux vnstat a Console Network Traffic Monitoring Tool

My Personal Notes arrow_drop_up
Recommended Articles
Page :