Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Monitor Network Usage for Linux Processes

Learn about Linux Process, including 1. Nethogs, key uses, practical steps, common issues, and answers to frequently asked questions.

Table of Contents

This practical guide explains how to monitor network usage for linux processes with clear steps and useful context. It also covers common requirements, potential problems, and the details that can help you get better results.

1. Nethogs

1. Nethogs - Linux Process

nethogs is a program that does the same Internet connections as htop or top does for CPU and memory usage. It shows you a quick look at which processes are accessing the network.

Like top, htop or atop, nethogs is a full screen program that updates every few seconds to show you current network connections in progress.

Installing nethogs is very simple. You just need to go through your package manager.

For example, on Debian and Ubuntu:

sudo apt install nethogs

And on Arch Linux:

sudo pacman -S nethogs

On the Red Hat family:

sudo dnf install nethogs

To run nethogs, you need to be root:

sudo nethogs

It is possible to set it up so that you can run nethogs as a regular user using this command:

sudo setcap "cap_net_admin,cap_net_raw+pe" /path/to/nethogs

You should replace "/path/to/nethogs" with the absolute pathname of nethogs. You can find this with the which command:

which nethogs

2. Lsof

2. Lsof - Linux Process

Although lsof is a utility to list open files, it can also list open network connections. The -i option lists the Internet connections associated with processes running on the system. After all, on Linux, everything is a file.

To see the current Internet connections, use this command:

lsof -i

lsof will show you the name of any command with an open Internet connection, its PID, file descriptor, Internet connection type, size, protocol, and the official file name of the connection.

Using the -i4 and -i6 options allows you to see connections that use IPv4 or IPv6.

You most likely have lsof installed already. It's also easy to install on major Linux distributions if you haven't already.

On Debian and Ubuntu, type:

sudo apt install lsof

And on Arch:

sudo pacman -S lsof

On the Red Hat distro line:

sudo dnf install lsof

3. Netstat

3. Netstat - Linux Process

netstat is a powerful program that allows you to view network connections on your system. It doesn't show you which network connection is attached. As with lsof, you can see this with a command line option.

netstat is part of the network tools package. You can install it on most Linux distributions using the default package manager.

For example, on Debian or Ubuntu:

sudo apt install net-tools

On Arch Linux:

sudo pacman -S net-tools

To install netstat on Fedora, CentOS and RHEL, run:

sudo dnf install net-tools

You can run netstat at the command line. By default, it will show you information like the protocol, address, and status of the connection, but the -p option adds a column showing the process ID and command name.

netstat -p

When you run it, netstat will just list all network connections and then exit. With the -c option, you can see a constantly updated list of connections:

netstat -pc

This would be similar to using a screen-oriented program like nethogs, but the advantage of doing it this way is that you can pipe the output to another program like grep or pager to check it out:

netstat -p | grep 'systemd'

To see all networked processes on your system, you may have to run netstat as root:

sudo netstat

Conclusion

Understanding Linux Process makes it easier to compare options, avoid common mistakes, and apply the information in this guide more effectively. Review the relevant requirements before making changes or choosing a solution.

FAQ

How do you monitor network usage for linux processes?

Follow the steps in this guide in order, confirm the required settings or tools, and verify the result before making additional changes.

Is it safe to monitor network usage for linux processes?

It is generally safe when you follow the recommended instructions, use trusted tools, and avoid changing settings you do not understand.

What should you do if the process does not work?

Recheck the requirements, restart the device or application when appropriate, and review each step for missed settings or compatibility issues.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.