Serverspace Black Friday
JH
Joe Harris
May 1, 2021
Updated June 7, 2023

How to Monitor Network Traffic with vnStat on Ubuntu 20.04

Linux Monitoring Networks Ubuntu

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 vnstat

You can verify the installation was successful and find out the version using the command:

vnstat -v

Output:

vnStat 2.6 by Teemu Toivola

Let's check that the service is running and is already analyzing traffic:

systemctl status vnstat

Output:

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 ago

If 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:

vnstat

To view statistics for every 5 minutes:

vnstat -5

For every hour:

vnstat -h

And this is how the bandwidth usage diagram will be built:

vnstat -hg

Statistics for days, months or years, respectively:

vnstat -d
vnstat -m
vnstat -y

Here's how you can see the top 10 days by overall channel usage:

vnstat -t

View summary statistics for 5 seconds in real time:

vnstat -tr

And so the utility will show what is happening at the current moment:

vnstat -l

If you have several network interfaces, you can select one of them by specifying its name as a parameter in the command:

vnstat -i interface-name

To disable monitoring of a specific interface and remove all statistics for it, use:

sudo vnstat --remove -i interface-name --force

To add it back after that:

sudo vnstat --add -i interface-name

To apply the settings after adding, you need to restart vnstat:

sudo systemctl restart vnstat

As you can see, vnStat is an easy-to-use yet useful tool for analyzing the use of network interfaces.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.