Install and Use vnStat on Debian 11

This tutorial intends to teach you How To Install and Use vnStat on Debian 11.

VnStat is a free, open-source, lightweight, and console-based Network Traffic monitor. Using VnStat, we can easily find how much network bandwidth is consumed and display the result hourly, daily, monthly, or for a specific time period.

Vnstat gathers the usage details of single or multiple Network interfaces and displays the summary in the command line. It also helps to calculate the approximate amount of Internet bandwidth usage per month or per day or for a particular period of time.

How To Install and Use vnStat on Debian 11

For installing vnStat, you need to log in to your server as a non-root user with Sudo privileges. To do this, you can follow our guide the Initial Server Setup with Debian 11.

Follow the steps below to install the latest version vnStat on Debian 11.

Install vnStat Network Traffic Monitoring Tool on Debian 11

First, you need to update your local package index by using the command below:

sudo apt update

Then, install the required packages and dependencies:

sudo apt install build-essential gcc make libsqlite3-dev

Next, use the wget command to download the vnStat LTS, which at the time of writing this post, is 2.9. To check the latest version, you can visit the vnStat Downloads page.


Extract your downloaded file:

tar -xvzf vnstat-2.9.tar.gz

With this command, a folder called vnstat-2.9 will be generated which you will need to access and from there configure the package for compilation.

Switch to your vnStat file:

cd vnstat-2.9

Now use the following command to configure the packages for compilation:

./configure --prefix=/usr --sysconfdir=/etc

At this point, use the commands below to compile the package and install vnStat:

# sudo make
# sudo make install

When you are done, verify your vnStat installation on Debian 11 by checking its version:

vnstat -v
vnStat 2.9 by Teemu Toivola <tst at iki dot fi>

How To Use vnStat command

Before you start to use the vnStat command, you need to start the vnStat service. As you have installed it manually, there is no service installed so you have to create it.

To create it we will use the example file that comes with the code we have just compiled:

sudo cp -v examples/systemd/vnstat.service /etc/systemd/system/

Then, reload the list of services:

sudo systemctl daemon-reload

Next, start and enable the vnStat service with the following commands:

# sudo systemctl enable vnstat
# sudo systemctl start vnstat

Verify that your vnStat is active and running on Debian 11:

sudo systemctl status vnstat
vnstat.service - vnStat network traffic monitor
Loaded: loaded (/etc/systemd/system/vnstat.service; enabled; vendor preset>
Active: active (running) since Sat 2022-06-11 05:58:21 EDT; 1min 9s ago
Docs: man:vnstatd(8)
Main PID: 9279 (vnstatd)
Tasks: 1 (limit: 2340)
Memory: 1.4M
CPU: 49ms
CGroup: /system.slice/vnstat.service
└─9279 /usr/sbin/vnstatd -n

After a few minutes you can start using vnStat:

Database updated: 2022-06-11 06:15:00

eth0 since 2022-06-11

rx: 729.57 KiB tx: 218.05 KiB total: 947.62 KiB

rx | tx | total | avg. rate
2022-06 729.57 KiB | 218.05 KiB | 947.62 KiB | 8 bit/s
estimated -- | -- | -- |

rx | tx | total | avg. rate
today 729.57 KiB | 218.05 KiB | 947.62 KiB | 345 bit/s
estimated 2.74 MiB | 837 KiB | 3.55 MiB |

By default, it takes the active interface, but you can change it:

vnstat -i [interface]

When an interface is monitored, a new database with logs is created. You can delete it and reset the statistics.

sudo vnstat -i [interface] --remove --force

In this case, you have to specify the interface to monitor.


At this point, you learn to Install and Use vnStat on Debian 11.

Hope you enjoy it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!