Ubuntu set up a Vnstat network traffic monitor console

How can I install vnstat – Network Traffic Monitor in console mode on Ubuntu to record 5 minutes, per hour, per day, per month and per year of network traffic for the selected interface?

This manual shows you how to install vnstat on a desktop or server based on Ubuntu Linux versions 16.04, 18.04 and 20.04 LTS. It is a free and open source console tool for monitoring network traffic. It is not a pocket sniffer. vnStat can also be used without root privileges. Let’s see how to install vnstat on the Ubuntu box.

Step 1 – Ubuntu installs vnstat with apt/apt-get

Enter the following apt/apt-get command for the system update:
sudo apt update
sudo apt upgrade
Find the vnstat package, Enter:
apt show vnstat
Example output :

Package: vnstat version
: 2.6-1
Priority: Not required
Section : Universe/Network
Origin : Ubuntu containers : Ubuntu developer <[email protected]>
container original : Christian Göttsche <[email protected]>
Error: https://bugs.launchpad.net/ubuntu/+bug
Game size: 310 kB
Dependent on: init system helpers (>= 1.54~)
Dependent on: libc6 (>= 2.29), libsqlite3-0 (>=, adduser, lsb base
Offers: vnstati
Homepage: https://humdi.net/vnstat/
Download size: 88.9 kB
APT sources: http://mirrors.linode.com/ubuntu network/universe amd64 Packages
vnStat – network traffic monitor in console mode for Linux. It records the daily
network traffic for the selected interface(s). vnStat is not a
packet sniffer. Traffic information is parsed from the /proc
file system, so vnStat can be used without root privileges.

Package: vnstat
Version: 2.6-1
Priority: optional
Section: universe/net
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Christian Göttsche <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 310 kB
Pre-Depends: init-system-helpers (>= 1.54~)
Depends: libc6 (>= 2.29), libsqlite3-0 (>=, adduser, lsb-base
Suggests: vnstati
Homepage: https://humdi.net/vnstat/
Download-Size: 88.9 kB
APT-Sources: http://mirrors.linode.com/ubuntu focal/universe amd64 Packages
Description: console-based network traffic monitor
vnStat is a network traffic monitor for Linux. It keeps a log of
daily network traffic for the selected interface(s). vnStat is not
a packet sniffer. The traffic information is analyzed from the /proc
filesystem, so vnStat can be used without root permissions.


Run the following command to configure and install vnstat on your Ubuntu server:
sudo apt-get install vnstat
sudo apt install vnstat
Ubuntu set up a Vnstat network traffic monitor console command

Step 2 – Setting up the circuit board

The default database directory for each interface is at the following location (use the ls/cd command):
cd /var/lib/vnstat/
ls -l /var/lib/vnstat/
Example output :

only 4
-rw-r–r— 1 vnstat vnstat 2792 23 apr 19:28 eth0

Use the ip command to get the name of your interface:
ip l show
ip a show

1 : Lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00 brd 00:00
2: enp0s31f6 : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel UP status of DEFAULT mode Default group qlen 1000
link/ether 40:9f:38:28:f6:b5 brd ff:ff:ff:fff

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 40:9f:38:28:f6:b5 brd ff:ff:ff:ff:ff:ff

Note the interface name enp0s31f6. We need to edit the /etc/vnstat.conf file with a text editor such as nano or vim:
sudo nano /etc/vnstat.conf
Set the default interface name to enp0s31f6 (or eth0 on older Ubuntu systems)
Interface enp0s31f6
We can configure the date output formats as follows

Monthly format %G%m%m
Higher format %G%m%m%m%D

DayFormat “%Y-%m-%d”
MonthFormat “%Y-%m”
TopFormat “%Y-%m-%d”

Define the storage duration (use -1 for unlimited and 0 for stop).

5 minutes 48
Operating hours 4
days 62
months 25
years -1
TopDayEnters 20

5MinuteHours 48
HourlyDays 4
DailyDays 62
MonthlyMonths 25
YearlyYears -1
TopDayEntries 20

Save the file and close it.

Step 3 – Activation and putting into service of the service TABLE

We will use the systemctl command to check the system, like vnstat.service on Ubuntu Linux. The syntax for service activation is as follows:
activate sudo systemctl vnstat.service

Start of TUNSTATservice

sudo systemctl Start vnstat.service

DWT service stop

sudo systemctl stop vnstat.service

Restart/resumption of Unstat service

After editing /etc/vnstat.conf, we need to restart or reboot the service:
sudo systemctl restart vnstat.service
sudo systemctl restart vnstat.service.

Search for operating status VNSTAT

sudo systemctl vnstat.service
Ubuntu set up a Vnstat network traffic monitor console

Step 4 – Display of network traffic diagrams

We’ve got two parts here:

  1. vnstatd daemon – A background service that monitors and updates the interface database according to /etc/vnstat.conf.
  2. vnstat command – a command-line tool for system administrators/developers to retrieve traffic information stored by the vnstat daemon. In other words, we need to use vnstat command.

To query the vnstat database, type the following command into the Ubuntu field:
Examples of outputs of a currently installed system

The database has been updated: 2020-04-23 19:39:00

and0 from 2020-04-23

Rx: 94.30 KiB tx : 113.71 KB in total : 208.01 KIB

monthly rx | tx | total | average

dailyrx | tx | avg.

Database updated: 2020-04-23 19:39:00
eth0 since 2020-04-23
rx: 94.30 KiB tx: 113.71 KiB total: 208.01 KiB
rx | tx | total | avg. rate
2020-04 94.30 KiB | 113.71 KiB | 208.01 KiB | 0 bit/s
estimated — | — | — |
rx | tx | total | avg. rate
today 94.30 KiB | 113.71 KiB | 208.01 KiB | 24 bit/s
estimated 114 KiB | 138 KiB | 252 KiB |

We can select the interface as follows:
vnstat -i eth0
Do you want to display a traffic overview to merge the interfaces eth0, eth2 and eth3? Try:
vnstat -i eth0+eth1+eth3
We can display all information about the tun0 VPN interface in xml format:
vnstat -i tun0 –xml
What about the Json format? Try:
vnstat –json
The following two special options can only be used with –json, –xml and Output List. Skip the -b option to start displaying the list with a specific date/time instead of selecting based on the number of items to be displayed. The date can only be in the formats YYYYY-MM-DD HH:MM and YYYYY-MM-DD. Another option -e to set the end date:
vnstat -b {YYYY-MM-DD} -i {interface} –xml
vnstat -e {YYYY-MM-DD} -i {interface} –json

You can delete the data in the database for the eth1 interface and terminate its monitoring in the following format:
vnstat -i eth1 –remove

Displays hourly traffic statistics

pbst -hpbst -i eth0 -h pbst, runs on Ubuntu and displays traffic per hour

Display of daily (daily) traffic statistics

vnstat -d
vnstat -i tun0 -d
Ubuntu set up a Vnstat network traffic monitor console

View monthly traffic statistics

pnst -m
Ubuntu set up a Vnstat network traffic monitor console

Show annual transport statistics


enp0s31f6 / per year

Year rx | tx | total | average.

enp0s31f6 / yearly
year rx | tx | total | avg. rate
2019 382.24 GiB | 78.11 GiB | 460.35 GiB | 125.39 kbit/s
2020 834.28 GiB | 345.17 GiB | 1.15 TiB | 1.03 Mbit/s
estimated 2.61 TiB | 1.08 TiB | 3.70 TiB |

The traffic statistics of recent years are shown above.

Show best traffic days

pnst -i eth0
Ubuntu set up a Vnstat network traffic monitor console

To display the current baud rate of the selected interface in real time beforeis interrupted

Another elegant option that displays real-time throughput and network statistics is displayed after a pause if the execution time was longer than 10 seconds:
vnst -l
vnst -i tun0 -l
vnst -i eth0 -l
Ubuntu set up a Vnstat network traffic monitor console


You’ve learned how to configure and install vnstat to get detailed statistics about your network traffic. I find this tool very useful for tracing traffic, and any sudden peak can be further investigated for DoS/DDoS or bot activity on web servers. I also install it on pfSense or on a Linux-based home router to monitor my bandwidth usage, especially when connecting a 5G/4G/LTE vi dongle. More information about the vnstat homepage can be found here.


Published: Vivek gears

The author is the creator of nixCraft and an experienced system administrator, DevOps engineer and Linux/Unix shell script trainer. Receive the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly by email.install vnstat ubuntu,vnstat pfsense,ubuntu monitor network traffic by process,vnstat not enough data available yet,red hat network bandwidth monitor,ubuntu data usage monitor,monitor bandwidth centos 7,vnstat raspberry pi

You May Also Like

Calculation Number of Days Between Two Dates

Topic: Delphi Language charlene44 wrote: 18/08/2006 at 15h08 calculation of number of…

Top Benefits of Social Media Marketing

We cannot deny the fact that when it comes to marketing, social…

World of Warcraft Classic: Some Players Use Illegal Tools to Stay Connected

Earlier this week, Blizzard released World of Warcraft Classic. The launch was,…

Crash Team Racing Bientt Back on Ps4!

Activision seems not to have finished with the remastering of the Playstation…