How to Install and Use vnstat Network Traffic Monitoring Tool in Linux?
Last Updated :
31 Oct, 2022
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
sudo apt-get install vnstatCheck 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 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]
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

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
/usr/bin/vnstat --hours

Displaying days based traffic:
/usr/bin/vnstat --days

Show months based traffic:
/usr/bin/vnstat --months

Calculate traffic:
/usr/bin/vnstat -tr

Show transfer rate in real-time:

Showing in online:

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

Similar Reads
How to Monitor Network Traffic Using Wireshark in Windows? Monitoring network traffic is critical for diagnosing network issues, analyzing performance, and enhancing security. Wireshark is an important and generally- used network protocol analyzer that allows you to capture and inspect packets in real- time on your Windows system. In this article, we will w
5 min read
How to Install and Use Wireshark on Ubuntu Linux? Wireshark is an open-source network protocol analyzer that helps us to see what is happening inside a network when we try to communicate with other networks. Currently, Wireshark is the most famous application to analyze networks. As the most popular network analyzer tool, Wireshark provides an in-d
3 min read
How to Install and Use Scout_Realtime to Monitor Server and Process Metrics in Linux? There are numerous free tools on Linux that are used to monitor the Linux system including hardware and software. We all may have already come across some command-line Linux performance monitoring tools such as top, htop, atop, etc. Alike that we come across another tool called Scout Realtime tool w
2 min read
Linux - Network Monitoring Tools Network monitoring is using a system (hardware or software) that continuously observes your network and the data flows through it, depending on how the monitoring solution actually functions and informs the network administrator. We can keep a check on all the activities of our network easily. While
4 min read
How to Install and Use Htop on Linux? Htop is a powerful and interactive system-monitoring tool for Linux, offering a real-time, user-friendly interface to track system performance. It provides detailed information on system processes, CPU usage, memory usage, and more. This guide will walk you through the steps to install and use Htop
3 min read
Linux - Monitoring Network Traffic With nethogs NetHogs is similar to Linux top command which is an open-source command-line program, that is used for monitoring network traffic in Linux. But do you ever wanted to notice which application in your system is eating up your bandwidth, Then Nethogs is one of the good choices. Nethogs will help you fi
5 min read