In this guide, we will be looking at how to install vnStat and monitor network traffic on Ubuntu OS.
Note: The procedure described here has been tested on Ubuntu 20.04 LTS. The commands have been executed on Terminal which you can open through the Ctrl+Alt+T shortcut.
VnStat is available in the default Ubuntu repositories but it is not the latest version. To install vnStat latest version, follow the below-mentioned steps:
First, execute the below command to update the system repository index:
Enter the password for sudo.
Next, you will have to install some prerequisites that can build software from source. We will need it for the compilation of vnStat. Execute this command to install the prerequisites:
Now from the vnStat official website, download the latest version of vnStat tar.gz package. Currently, the latest version of vnStat is 2.6, so we can download it as follows:
Once the tar.gz package is downloaded, we can install it as follows:
First, extract the tar.gz using the below command in Terminal:
Then switch to the resulting extracted directory using the below command:
Now configure it using the command below:
Then, install vnStat as follows:
To verify if vnStat has been successfully installed, execute the below command in Terminal:
The following output confirms vnStat version 2.6 has been installed.
To enable and start vnStat service, first you will need to copy vnStat service file from the vnStat extracted directory to the /etc/systemd/system/ using the below command:
Now enable vnStat service using the below command:
Then to start vnStat service, execute the below command
To verify if vnStat service is running, execute the below command:
The following output confirms vnStat service is running properly without any issues.
vnStat supports various options that help you to monitor traffic in different ways. You can view some of the available options by executing the below command in Terminal:
Or execute the following command to view the complete list of options:
You can also visit vnStat man page for the complete list of options.
Running the vnStat command without any option prints the bandwidth usage statistics for all the available interfaces.
Here is the output of vnStat command on our system which is showing statistics of one interface as this is the only available interface on our system.
You can also monitor a specific interface by using the -i option followed by the interface name.
For instance, to monitor an interface ens33, the command would be:
You can also monitor bandwidth usage as per hourly, daily, monthly, and yearly usage using the -h, -d, -m, and -y options respectively. For example, to find the daily bandwidth usage, the command would be:
You can also get the bandwidth usage for the top traffic days. For instance, to find the top 10 bandwidth usage days, use -t option followed by the number of days:
To monitor bandwidth usage in real-time, use the -l option as follows:
If you want to remove all the statistics for a specific interface from the database and stop monitoring it, use the below command syntax:
For instance, to remove the interface ens33 from the database and stop monitoring it, the command would be:
To add this interface again for monitoring, use the below command:
After adding the interface, restart vnStat service:
vnStat is a handy tool to keep an eye on the bandwidth usage on your Linux OS. In this guide, you have learned how to install and use this tool on Ubuntu 20.04 LTS for monitoring the traffic on network interfaces.
In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…
In this article, we will see how to install clang tool on Ubuntu or Debian…
When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…
You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…
Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…
System hardening means locking down a system and reducing its attack surface: removing unnecessary software…