How to Install and Use vnstat Network Traffic Monitoring Tool in Linux?
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
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]
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
This will be the following result:
Sometimes you may find the following error:
Now, we have to make vnstat daemon auto-start at boot by typing the following command:
sudo systemctl enable vnstat.service
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
Displaying days based traffic:
Show months based traffic:
Show transfer rate in real-time:
Showing in online:
For getting more info follow the manual by typing the following command: