9 C
Texas
angeloma
Senior Writer and partner

Install and use vnStat on Debian 11 / 10

Hello, friends. In this post, you will learn how to install and use vnStat on Debian 11 / 10. With this tool, you will be able to monitor a network interface quickly.

What is vnStat?

The best definition of Vnstat can be found on the project’s own website:

vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as an information source. This means that vnStat won’t actually be sniffing any traffic and also ensures light use of system resources regardless of network traffic rate.

Therefore this tool is quite well known within the community and among sysadmins. It is quite simple to use and as you will see below it is easy to install.

Install vnStat on Debian 11 / 10

One of the fastest and most immediate ways to install vnStat on Debian 11 / 10 is to install it from the official repositories.

- Advertisement -

Although this is not the only way to get the program, it is the easiest method for newbies.

So, open a terminal or from an SSH session, install the security patches in the distribution:

sudo apt update
sudo apt upgrade

Next, you can install the vnStat package as follows:

sudo apt install vnstat

After it is installed, start the application service.

sudo systemctl start vnstat

This will complete the installation and you will be able to use it.

Install the latest version of vnStat on Debian 11 / 10

The previous method has a big problem and it is that the version that appears in the official repositories of Debian 11 / 10, is very outdated. So it is advisable to always install the latest version following these steps that I will describe.

First, install the packages needed to do the compilation, as well as some dependencies:

sudo apt install build-essential gcc make libsqlite3-dev

Then download the latest stable version, which at the time of writing this post, is 2.8.

wget https://humdi.net/vnstat/vnstat-2.8.tar.gz

Decompress the downloaded file

tar -xvzf vnstat-2.8.tar.gz

As a result of executing the above command, a folder called vnstat-2.8 will be generated which you will need to access and from there configure the package for compilation:

cd vnstat-2.8
./configure --prefix=/usr --sysconfdir=/etc

Now, compile the package and install it with this pair of commands:

sudo make
sudo make install

If everything went well, you will be able to run the vnstat command and display, for example, the installed version:

vnstat -v

Output:

vnStat 2.8 by Teemu Toivola <tst at iki dot fi>

Using the vnStat command

Before using the tool it is necessary to start the vnStat service. As we have installed it manually, there is no service installed so we have to create it.

Fortunately, 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/

Refresh the list of services

sudo systemctl daemon-reload

And now yes, enable it so it can start with the system and start the service

sudo systemctl enable vnstat
sudo systemctl start vnstat

And check the status of the service

sudo systemctl status vnstat
● vnstat.service - vnStat network traffic monitor
     Loaded: loaded (/etc/systemd/system/vnstat.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-10-02 18:24:27 CEST; 11s ago
       Docs: man:vnstatd(8)
             man:vnstat(1)
             man:vnstat.conf(5)
   Main PID: 5939 (vnstatd)
      Tasks: 1 (limit: 2276)
     Memory: 612.0K
        CPU: 20ms
     CGroup: /system.slice/vnstat.service
             └─5939 /usr/sbin/vnstatd -n

Oct 02 18:24:27 osradar systemd[1]: Started vnStat network traffic monitor.
Oct 02 18:24:27 osradar vnstatd[5939]: Info: vnStat daemon 2.8 started. (pid:5939 uid:0 gid:0 64-bit)
Oct 02 18:24:27 osradar vnstatd[5939]: Info: Monitoring (1): eth0 (1000 Mbit)

After waiting a few minutes, you can start using it.

vnstat
1.- vnStat on Debian 11/ 10
1.- vnStat on Debian 11/ 10

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.

Enjoy it.

Conclusion

So now you know how to install and use vnStat on Debian 11 / 10 This command although simple allows you to find answers to the operation of a network interface and to know if the behavior is as expected…

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article