RHEL BasedRocky Linux

How To Install VnStat on Rocky Linux 9

Install VnStat on Rocky Linux 9

In this tutorial, we will show you how to install VnStat on Rocky Linux 9. For those of you who didn’t know, Monitoring network bandwidth usage is crucial for troubleshooting, capacity planning, and optimizing internet connectivity. vnStat is a lightweight, open-source, and console-based network traffic monitoring tool that provides detailed insights into your Linux system’s network activity.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the VnStat network traffic monitor on Rocky Linux 9 or RHEL-based.

Prerequisites

  • A server running one of the following operating systems: Rocky Linux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install VnStat on Rocky Linux 9

Step 1. Update Your System.

The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf update
sudo dnf install epel-release

Step 2. Installing vnStat on Rocky Linux 9.

With the prerequisites in place, you can install vnStat using the dnf package manager. Open your terminal and execute the following command:

sudo dnf install vnstat

During the installation process, dnf will resolve dependencies and set up the required packages. Once completed, verify the installation by checking the vnStat version:

vnstat --version

You should see the installed version printed in the terminal output.

Step 3. Configuring vnStat.

After installation, vnStat requires some initial configuration to start monitoring network interfaces.

  • Identifying Network Interfaces

First, identify the network interfaces on your system using the ip addr command:

ip addr

This will list all available network interfaces, including their names (e.g., enp0s3, enp0s8) and IP addresses.

  • Creating a Database

vnStat stores network traffic data in a database for each monitored interface. To create a database for your primary network interface (e.g., enp0s3), run:

sudo vnstat -u -i enp0s3

This command initializes the database for the specified interface. You can repeat this step for additional interfaces you want to monitor.

After creating the database, start the vnStat service to begin monitoring network traffic:

sudo systemctl start vnstat

To ensure vnStat starts automatically after system reboots, enable the service:

sudo systemctl enable vnstat

Step 4. Using vnStat.

With vnStat configured and running, you can now access various network traffic statistics and visualizations.

  • Viewing Live Traffic

To view real-time network traffic for a specific interface (e.g., enp0s3), use the following command:

vnstat -l -i enp0s3

This will display the current transfer rate, showing the received (rx) and transmitted (tx) traffic in real time until you interrupt the process (Ctrl+C).

  • Hourly Traffic Statistics

To view hourly traffic statistics for the last 24 hours on an interface, run:

vnstat -h -i enp0s3

This command will generate a table showing the hourly network usage, helping you identify peak usage times.

  • Daily Traffic Statistics

For a summary of daily network traffic over the last 30 days, use:

vnstat -d -i enp0s3

This report can help you track daily bandwidth consumption patterns.

  • Monthly Traffic Statistics

To view monthly network traffic data, execute:

vnstat -m -i enp0s3

This command displays a table with monthly bandwidth usage, which can be useful for monitoring long-term trends.

  • Top 10 Days by Bandwidth Usage

If you want to see the top 10 days with the highest bandwidth consumption, run:

vnstat -t -i enp0s3

This report can help identify periods of unusually high network activity, which may require further investigation.

  • Monitoring Multiple Interfaces

If your Rocky Linux system has multiple network interfaces, you can monitor them simultaneously with vnStat. First, create a database for each interface using the -u -i option, as shown earlier. Then, when querying traffic statistics, specify the desired interface with the -i flag.

For example, to view daily traffic for interfaces enp0s3 and enp0s8, run:

vnstat -d -i enp0s3
vnstat -d -i enp0s8

Congratulations! You have successfully installed VnStat. Thanks for using this tutorial for installing the VnStat network traffic monitor on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official VnStat website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button