How to Monitor Network Traffic with vnStat on Ubuntu 20.04
vnStat monitors traffic on network interfaces and records data. Thus, with its help, we can find out the statistics of bandwidth usage over a certain period of time.
Installing vnStat on Ubuntu 20.04
vnStat is available from the official Ubuntu 20.04 repositories. At the time of writing this tutorial, it contains the latest version. Let's first update the list of repositories and then install:
sudo apt update
sudo apt install vnstatYou can verify the installation was successful and find out the version using the command:
vnstat -vOutput:
vnStat 2.6 by Teemu ToivolaLet's check that the service is running and is already analyzing traffic:
systemctl status vnstatOutput:
vnstat.service - vnStat network traffic monitor
Loaded: loaded (/lib/systemd/system/vnstat.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-04-03 02:22:28 UTC; 9min agoIf you see enabled and active (running), then everything is working.
Viewing network statistics with vnStat
Right after installation, you need to wait a while for the statistics to accumulate.
To view data for all time and for all network interfaces, run vnstat without parameters:
vnstatTo view statistics for every 5 minutes:
vnstat -5For every hour:
vnstat -hAnd this is how the bandwidth usage diagram will be built:
vnstat -hgStatistics for days, months or years, respectively:
vnstat -d
vnstat -m
vnstat -yHere's how you can see the top 10 days by overall channel usage:
vnstat -tView summary statistics for 5 seconds in real time:
vnstat -trAnd so the utility will show what is happening at the current moment:
vnstat -lIf you have several network interfaces, you can select one of them by specifying its name as a parameter in the command:
vnstat -i interface-nameTo disable monitoring of a specific interface and remove all statistics for it, use:
sudo vnstat --remove -i interface-name --forceTo add it back after that:
sudo vnstat --add -i interface-nameTo apply the settings after adding, you need to restart vnstat:
sudo systemctl restart vnstatAs you can see, vnStat is an easy-to-use yet useful tool for analyzing the use of network interfaces.
700
300
700
300
700
300