vnstat command in Linux with Examples
Last Updated :
16 Oct, 2024
vnstat is a command-line tool in Linux that is generally used by system administrators in order to monitor network parameters such as bandwidth consumption or maybe some traffic flowing in or out. It monitors the traffic on the system’s network interfaces.
Installing vnstat on Linux
In case of RedHat-based Linux
yum install vnstat
In case of a ubuntu or Debian Linux
apt install vnstat
Working with vnstat Command
1. To get basic stats of all network interfaces
To see an overview of the network traffic on all connected interfaces:
vnstat

This command will print all the basic stats of the network interfaces connected to the system.
2. To monitor a specific interface
If you want to focus on a specific network interface, use the -i option to specify the interface name:
vnstat -i wlo1

This will monitor and display the stats of the specified interface that is wlo1.
3. To get the daily stats of an interface
To view daily traffic stats on a particular interface:
vnstat -d -i wlo1

This will print the daily stats of the specified interface which is wlo1.
4. To get the hourly stats of an interface
For more granular data, you can check hourly stats with:
vnstat -h -i wlo1

This will print the hourly stats of the specified interface which is wlo1.
5. To display the monthly stats of a interface
To get a broader view of network usage, use the following command to see monthly statistics:
vnstat -m -i wlo1

This command will display the monthly stats of the specified interface.
6. To save output to a XML file
If you need to export your network traffic data in XML format for further analysis or automation, use this command:
vnstat --xml -i wlo1 >output.xml

The command will create an XML file with name output.xml and will have the output of the command in XML format.
7. To save output to a JSON file
For those working with data pipelines or web applications, you may want the data in JSON format. Use the following command:
vnstat --json -i wlo1 >output.json

This command will create a JSON file with name output.json and will have the output of the command in JSON format.
8. To save output to a text file
To save the output in a simple text file format, you can use:
vnstat --oneline -i wlo1 >output.txt

This command will create a text file with name output.txt and will have the output in a one-line format.
9. To calculate traffic on the current interface
If you want to see real-time network traffic statistics, you can use the -tr option:
vnstat -tr

This command will display the traffic on the current network interface in use.
10. To display vnstat help
To learn more about vnstat and its available options, run the help command:
vnstat --help

This command will display the vnstat help section.
Conclusion
The vnstat command is a powerful and flexible tool for monitoring network traffic on Linux systems. Whether you are a system administrator looking to track bandwidth usage or simply someone interested in analyzing network performance, vnstat provides a range of features that cater to both basic and advanced needs.
vnstat command in Linux – FAQs
What is the purpose of the vnstat command?
vnstat is a command-line tool used to monitor network bandwidth and traffic on Linux systems. It tracks data usage over time by monitoring network interfaces and provides detailed stats such as daily, hourly, and monthly data.
How do I view basic stats for all network interfaces using vnstat?
You can view the overall network statistics of all interfaces by simply running:
vnstat
How can I monitor a specific network interface?
To monitor a specific network interface, use the -i flag followed by the interface name:
vnstat -i wlo1
How can I view real-time network statistics using vnstat?
To view real-time network traffic for a specific interface (e.g., eth0), you can use the following command:
vnstat -l -i eth0
Similar Reads
until command in Linux with Examples
until command in Linux is used to execute a set of commands as long as the final command in the 'until' Commands has an exit status that is not zero. It is mostly used where the user needs to execute a set of commands until a condition is true. Syntaxuntil COMMANDS; do COMMANDS; donewhere, CONDITION
2 min read
Linux | Uptime command with examples
It is used to find out how long the system is active (running). This command returns set of values that involve, the current time, and the amount of time system is in running state, number of users currently logged into, and the load time for the past 1, 5 and 15 minutes respectively. Linux uptime S
5 min read
How to add User in Linux | useradd Command
useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with the system whereas adduser is a Perl script that uses useradd binary in the
5 min read
usermod command in Linux with Examples
usermod command or modify user is a command in Linux that is used to change the properties of a user in Linux through the command line. After creating a user we have to sometimes change their attributes like password or login directory etc. so in order to do that we use the Usermod command. The info
4 min read
username Command in Linux With Examples
Linux as an operating system holds the capabilities of handling multiple users. So it is important to keep a check on the users and their related information in order to maintain the integrity and security of the system. Whenever a user is added its information is stored in the "/etc/passwd" file. I
3 min read
users command in Linux with Examples
users command in Linux system is used to show the user names of users currently logged in to the current host. It will display who is currently logged in according to FILE. If the FILE is not specified, use "/var/run/utmp". "/var/log/wtmp" as FILE is common. Syntaxusers [OPTION]... [FILE]where, OPT
2 min read
How to Delete User in Linux | userdel Command
Managing user accounts is an essential aspect of Linux system administration. Understanding how to delete a user in Linux is crucial, whether you need to remove an unused account, revoke access for a departing employee, or clean up your system for security reasons. Here, we will explore the 'userdel
6 min read
vi Editor in Linux
The default editor that comes with the Linux/UNIX operating system is called vi (visual editor). Using vi editor, we can edit an existing file or create a new file from scratch. we can also use this editor to just read a text file. The advanced version of the vi editor is the vim editor. Table of C
9 min read
vmstat command in Linux with Examples
vmstat command in Linux/Unix is a performance monitoring command of the system as it gives the information about processes, memory, paging, block IO, disk, and CPU scheduling. All these functionalities makes the command vmstat also known as virtual memory statistic reporter. The very first report pr
3 min read
vnstat command in Linux with Examples
vnstat is a command-line tool in Linux that is generally used by system administrators in order to monitor network parameters such as bandwidth consumption or maybe some traffic flowing in or out. It monitors the traffic on the system's network interfaces. Installing vnstat on LinuxIn case of RedHa
4 min read