Hello, friends. In this post, you will learn how to install and use vnStat on Debian 10. With this tool, you will be able to monitor a network interface quickly.
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.
One of the fastest and most immediate ways to install vnStat on Debian 10 is to install it from the official repositories.
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.
The previous method has a big problem and it is that the version that appears in the official repositories of Debian 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
Decompress the downloaded file
tar -xvzf vnstat-2.6.tar.gz
As a result of executing the above command, a folder called
vnstat-2.6 will be generated which you will need to access and from there configure the package for compilation:
cd vnstat-2.6 ./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 2.6 by Teemu Toivola <tst at iki dot fi>
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 Mon 2021-04-12 23:58:19 CEST; 5s ago Docs: man:vnstatd(8) man:vnstat(1) man:vnstat.conf(5) Main PID: 7526 (vnstatd) Tasks: 1 (limit: 2296) Memory: 1.5M CGroup: /system.slice/vnstat.service └─7526 /usr/sbin/vnstatd -n Apr 12 23:58:19 osradar systemd: Started vnStat network traffic monitor. Apr 12 23:58:19 osradar vnstatd: No interfaces found in database, adding available interfaces... Apr 12 23:58:19 osradar vnstatd: Interface "eth0" added with 1000 Mbit bandwidth limit. Apr 12 23:58:19 osradar vnstatd: -> 1 new interface found. Apr 12 23:58:19 osradar vnstatd: Limits can be modified using the configuration file. See "man vnstat.conf". Apr 12 23:58:19 osradar vnstatd: Unwanted interfaces can be removed from monitoring with "vnstat --remove". Apr 12 23:58:19 osradar vnstatd: Info: vnStat daemon 2.6 started. (pid:7526 uid:0 gid:0 64-bit) Apr 12 23:58:19 osradar vnstatd: Info: Monitoring (1): eth0 (1000 Mbit)
After waiting a few minutes, you can start using it.
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.
So now you know how to install and use vnStat on Debian 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…