Have you ever been in a situation when working on your system with limited bandwidth and wondered what program is consuming your bandwidth. Nethogs is an application that can help you to find which program is responsible for it. It groups bandwidth by process on a network interface that is sending or receiving the network traffic. Nethogs is a handy application especially when there is a sudden spike in network traffic, you may use it to figure out which PID is causing this.
In today’s post, we will install Nethogs on the CentOS 8 system. Remember, you will be required to run the commands as sudo or as a root user in order to install and run Nethogs.
Installing Nethogs on CentOS
Nethogs is not available in the package repositories of CentOS. You can install Nethogs by first adding the EPEL repository. Below are the steps for installation of Nethogs on CentOS:
Step 1: Adding EPEL Repository
First, use the command below to add the EPEL repository:
$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Enter sudo password. During installation, it will prompt you with y/n option for proceeding with the installation procedure. If you want to proceed, press y and then Enter.
Then you will be prompted with y/n for the GPG key. Press y and then hit Enter to accept the key.
Once the EPEL repository is added, you will see the below output in the end.
Step 2: Installing Nethogs
Now you can install Nethogs on your CentOS system. Use the command below to do so:
$ sudo yum install nethogs
During installation, it will prompt you with y/n option for proceeding with the installation procedure. If you want to proceed, hit y and then Enter. Now the installation of Nethogs will be initiated on your machine.
Once Nethogs is installed, you will see the below output in the end.
Step 3: Verifying Installation
To verify the installation of Nethogs, use the command below:
$ sudo nethogs -v
The output below confirms that Nethogs 0.8.5 has been installed on our machine.
Step 4: Using Nethogs
The general syntax to use Nethogs is as follows:
$ sudo nethogs [option] [interface_name]
Nethogs collects information from the files located in the /proc directory. The output lists all the processes along with their PIDs that are sending and receiving the network packets on network interfaces. It then becomes easier to identify which process is consuming more bandwidth.
If you do not specify any option or interface name, Nethogs display the bandwidth information for all the interfaces.
$ sudo nethogs
To monitor a single network interface, use the nethogs command as follows:
$ sudo nethogs ens37
If your system has multiple network interfaces and you only want to monitor specific interfaces, you can specify it as follows:
$ sudo nethogs ens33 ens37
By default, Nethogs refreshes the output every second. You can change this interval using the -d option. To set the refresh interval to 2 seconds, the command would be:
$ sudo nethogs -d2
When Nethogs is running, you can use some options which are as follows:
- m: Pressing the m key at runtime, you can change the units for the displayed bandwidth (KB, B, MB and KB/s)
- r: Pressing the r key at runtime, you can sort the output by the traffic RECEIVED by the interface
- s: Pressing the s option at runtime, you can sort the output by the traffic SENT from the interface
- q: Pressing the q key at runtime, you can quit the shell
For more information about Nethogs, use the -h option as follows:
$ sudo nethogs -h
You can uninstall Nethogs as follows:
$ sudo yum remove nethogs
Enter sudo password. Now it might prompt you with y/n option for proceeding with the removal procedure. If you want to proceed, press y and then Enter. Nethogs will then be removed from your CentOS system.
Nethogs lets you view the bandwidth usage by your programs in order to help you figure out which processes are hogging your network bandwidth. Using the method described above, you can conveniently install and use Nethogs on the CentOS system. In case you want to uninstall Nethogs, its procedure is also described above.