Use Nethogs To Monitor Network Bandwidth Usage
Nethogs is a network monitoring tool to identify the processes that consume a large amount of bandwidth on a network interface. Thus, it is super-helpful for both network and system admins.
So, when network performance is affected and you need to quickly find where the issue is, Nethogs helps you with the same.
Other tools organise data by protocol or subnet, but Nethogs presents data by process. Therefore, administrators can identify the exact process causing the issue. Nethogs also supports multiple interfaces. So, admins can also monitor more than one network at the same time.
Now, in this article, we will explore how to install and use Nethogs on CentOS 6.x.
Getting Started – Prerequisites
Before the installation of Nethogs, you need to have a CentOS 6.x 64-bit server with a sudo user set up.
Also, you will need access to a terminal on this server, as you will be running some commands to install the necessary dependencies and Nethogs itself.
Installing Nethogs
The first thing to do is ensure that the EPEL (Extra Packages for Enterprise Linux) repository is available on your system. This repository contains the Nethogs package.
You can add this repository and install Nethogs by following these steps:
- Install the EPEL repository by running the following command:
sudo yum -y install epel-release
- Update the system packages to ensure you are working with the latest versions:
sudo yum -y update
- Clean up any cached packages:
sudo yum clean all
- Finally, install Nethogs with this command:
sudo yum -y install nethogs
Running Nethogs
- You can start using Nethogs to monitor bandwidth usage on your server after installation. Run Nethogs using the following command:
sudo nethogs
- This will launch Nethogs, and the tool will begin monitoring the default network interface on your server.Monitor a specific interface, like eth1 or em0, by specifying the interface in the command:
sudo nethogs eth1
- Monitor multiple interfaces all at once. You can add them in a single command like this:
sudo nethogs eth0 eth1
Understanding the Nethogs Interface
Nethogs will display a list of processes that are using network bandwidth when you run it.
Each process will have respective details such as its ID (PID), the user who is running it, and the bandwidth that it is consuming. So, it becomes easier to identify which process is responsible for heavy network usage.
You can also toggle between total traffic and instantaneous speed by pressing m inside the interface.
Quit Nethogs by pressing q.
Additional Commands for Nethogs
Nethogs offers some useful options to fine-tune how it works:
Adjust the refresh rate
Nethogs updates every second by default. You can change the refresh rate using the -d flag. For example, setting a 3-second refresh rate with –
sudo nethogs -d 3
View version info of installed Nethogs
nethogs -V
Trace mode
See the connections one by one in detail using the -t flag, running Nethogs in trace mode –
sudo nethogs -t
Bughunt mode
This mode is used to help find bugs (not recommended for regular use). You can enable it with:
sudo nethogs -b
Promiscuous mode
Run Nethogs in promiscuous mode to capture packets from all network interfaces. (not typically recommended due to the additional load) –
sudo nethogs -p
Help command
You can always display the help menu to get more information about the available options.
nethogs -h
Conclusion
By following these steps, you will be able to use Nethogs to its full potential on your CentOS system. It is a great tool for tracking down a resource-heavy process or getting a clearer view of network activity for network and system administrators.