In this article, we will explain a few tools that will allow you to check network usage per process in your Linux system. These tools include IPTraf, Iftop and Nethog. With the help of these tools, you can identify which process or port number is draining much of the network bandwidth.
Note that we have explained the procedure on Ubuntu 18.04 LTS system.
IPTraf is an open-source command-line network monitoring tool that allows monitoring of various network statistics such as TCP, UDP, Ethernet load, ICMP, etc. We can use it to view network usage of a processes running in Linux.
IPTraf is included in the official repositories of the Ubuntu system. Therefore, we can install it using the apt or apt-get command.
Open the Terminal by using Ctrl+Alt+T shortcut and then run this command as sudo to install IPTraf:
During installation, the system might ask for confirmation by providing with Y/n option. Hit y to confirm and then wait for a while until the IPTraf is installed on your system.
To use IPTraf, run this command in Terminal:
When you run the above command, you will see the output similar to below. The output shows the network statistics against the source IP address and port number. However, it does not show the specific process which is using the bandwidth.
For some common ports, you can easily guess the process name, such as FTP port number 21, telnet port number 23 and so on. However for some less known ports, to find out a process running against it, use the following netstat command:
For instance, we want to find out the process name against the port number 443. In that case, the command would be:
The output shows the process name “firefox” running against the port number 443.
To view network statistics for a particular interface, use –i followed by interface name:
To view more information about IPTraf, see the man page or use help as follows:
Iftop is similar to the top command except it is used for monitoring network usage instead of processor usage. It is an open-source command-line tool that displays current bandwidth usage of a specific interface. Similar to the IPTraf, it also does not displays the process which is using the bandwidth.
Iftop is available in the official repositories of Ubuntu. Therefore, we can install it simply using the apt or apt-get command.
In the Terminal, run this command as sudo to install Iftop:
During installation, the system might ask for confirmation by providing with Y/n option. Hit y to confirm and then wait for a while until the Iftop is installed on your system.
To use Iftop, run this command in Terminal:
It displays the sent and received bytes within three different time intervals. At the end, it displays cumulative sent and receive bytes.
To view port number in the display, use –p option as follows:
To view information about the specific interface, use –i option as follows:
To view more information about iftop, see the man page or use help as follows:
Nethogs is an open-source command-line utility that allows viewing network usage of a process running in the Linux system. Unlike the above IPTraf and Iftop tools, Nethogs sorts the output by process and bandwidth usage. Therefore, it comes handy when you need to find which process is using more bandwidth.
It is also available in the official Ubuntu repositories. Therefore to install it, use the apt or apt-get command as follows:
Wait for a while until the installation of Nethogs is completed.
To use Nethog for checking network usage, simply type nethogs in the Terminal:
The output displays the sent and received traffic used by different processes. In the end, it displays the total traffic sent and received by all processes.
To view network usage on a specific interface, use the Nethog command as follows:
To specify refresh interval, use –d option. For instance, to set 7 seconds as refresh interval, run this command:
That is all there is to it! In this article, we have learned how to install and use IPTraf, Iftop, and Nethog in Linux. Through these tools, you can easily check the network usage per process in your Linux system.