Nethogs is a Linux command that allows us to view network usage of a running process in realtime. Nethogs sorts the output by process and network bandwidth usage.
We can quickly find out which process is using more bandwidth. This is an important command when we troubleshoot network problems in realtime.
- How to install nethogs on Ubuntu or Debian
- How to install nethogs on CentOS or Redhat
- How to use nethogs to check network usage by process?
- How to change display modes from kb/s to mb/s in nethogs?
- How to use nethogs to monitor network interface bandwidth?
- How to use nethogs in interactive mode?
Understanding nethog command in Linux
The nethog command is a utility for monitoring network traffic in real time. The output of the command shows details about the data being transferred, including the source and destination IP addresses, port numbers, and protocol information.
The nethog command can be used to monitor traffic for a specific interface, process, TCP connection, or UDP connection. The command can also be used to generate a report of network traffic for a specific time period.
How to install nethogs on Ubuntu or Debian
Nethog is not installed on Ubuntu by default. Nethogs is available in the official package repository of Ubuntu/Debian. We can easily install nethogs with the APT command.
$ sudo apt update
$ sudo apt install nethogs
How to install nethogs on CentOS or Redhat
Nethogs is not installed on CentOS or Redhat by default. Nethogs is available in the EPEL repository. We can easily install nethogs from the EPEL repository with the YUM package manager.
$sudo yum install nethogs
How to use nethogs to check network usage by process in Linux?
We can run command nethogs to start nethogs with root user. The network upload (sent) and download (received) speeds for each process is listed. The network interface for each process is listed.
The owner of the process and also the PID is listed. If we have any process which is eating up network bandwidth unnecessarily, we can just kill the process using the PID.
Nethogs automatically updates the information just like top and htop does.
This will display the network bandwidth used by each process on the eth0 network interface.
The nethogs command can be useful for troubleshooting network issues. If a process is using a lot of bandwidth, it can be identified with the nethogs command.
How to change display modes from kb/s to mb/s in nethogs?
By default, nethogs displays the network download and upload speeds in kilobytes/s (kb/s). This is one of the display modes of nethogs. There are 4 display modes of nethogs, the default kb/s, total bytes used (b), total kilobytes used (kb), total megabytes used (mb).
We can press the m key on our keyboard to change this.
How to use nethogs to monitor network interface bandwidth in Linux?
$ sudo nethogs eth0
$ sudo nethogs –d 5 eth0 ( 5 is the interval)
How to use nethogs in interactive mode?
Following are some useful interactive controls (Keyboard Shortcuts) of nethogs command.
- -m : Change the units displayed for the bandwidth in units like KB/sec -> KB -> B-> MB.
- -r : Sort by magnitude of respectively traffic.
- -s : Sort by magnitude of sent traffic.
- -q : Hit quit to the shell prompt.