How to Install and Use vnStat Network Traffic Monitoring Tool in Linux
How to Install and Use vnStat Network Traffic Monitoring Tool in Linux
vnStat is a lightweight network traffic monitoring tool that keeps track of bandwidth usage without requiring root privileges to collect data. It’s perfect for Linux users who want to monitor and analyze their network usage over time. In this guide, you’ll learn how to install and use vnStat on Linux.
Step 1: Install vnStat
The vnStat tool is available in most Linux distributions’ package managers. Here’s how to install it on various systems:
For Ubuntu/Debian:
sudo apt update
sudo apt install vnstat
For Fedora:
sudo dnf install vnstat
For Arch Linux:
sudo pacman -S vnstat
For Other Distributions: You can build it from source if it’s not in your package manager. First, download the latest version from the official vnStat website:
wget https://humdi.net/vnstat/vnstat-2.x.tar.gz
tar -xvzf vnstat-2.x.tar.gz
cd vnstat-2.x
make
sudo make install
Step 2: Enable and Start the vnStat Service
After installation, you need to start the vnStat service to begin monitoring network traffic.
For Systemd-based distributions:
sudo systemctl enable vnstat
sudo systemctl start vnstat
For non-Systemd systems: Simply run the daemon using:
sudo vnstatd -d
This will start the vnStat daemon, which will monitor network traffic in the background.
Step 3: Check Network Interfaces
Before using vnStat, ensure that it’s monitoring the correct network interface. You can list all available interfaces using:
vnstat –iflist
Once you know the name of the interface (e.g., eth0, wlan0), you can view traffic statistics for that interface:
vnstat -i eth0
Step 4: Display Traffic Statistics
Now that vnStat is running, you can check your network usage statistics. There are various commands for viewing this data:
Daily Traffic:
vnstat -d
Hourly Traffic:
vnstat -h
Monthly Traffic:
vnstat -m
Live Traffic:
vnstat -l
This live mode displays network traffic in real-time.
Step 5: Export Traffic Data
You can also export network traffic data to a file for further analysis or reporting. To export data in a plain text format:
vnstat –export –json > vnstat_data.json
This can be useful if you want to integrate vnStat data with other tools or scripts.
Step 6: Customize vnStat
The vnStat configuration file is typically located in /etc/vnstat.conf. You can edit this file to customize the tool’s behavior, including the interval for data updates, the network interface to monitor, and more.
To open the configuration file:
sudo nano /etc/vnstat.conf
If you want, you can read our ngrep article by clicking the link below. Thank you for visiting us.
How to Analyze Network Packets with ngrep
If you would like to improve yourself in server management, you can purchase a server from our site, experiment and improve yourself in an affordable and reliable environment. I wish you good luck.
Conclusion
vnStat is a robust and efficient tool for monitoring network traffic on Linux systems. It’s easy to set up, lightweight, and doesn’t consume a lot of system resources. By following this guide, you can quickly install and configure vnStat to keep track of your bandwidth usage over time.
For more information and advanced usage, refer to the official vnStat documentation.
This guide provides all the necessary steps to install and use vnStat on Linux, allowing you to monitor network traffic with ease.