Monitoring bandwidth on Linux with Nethogs

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, colleagues. It is the task of any computer scientist to know how to manage the bandwidth of a computer. Especially if this computer is a server or a production computer that needs to know how the bandwidth is spent. So, in this post, you will learn how to monitor bandwidth in Linux. For this, we will use a CLI tool called NetHogs. Sounds interesting? So, let’s go for it.

NetHogs allows us to monitor the bandwidth of our system.

NetHogs is a small ‘net top’ tool. Instead of breaking the traffic down per protocol or subnet, like most tools do, it groups bandwidth by process. All this is according to the Project Github profile.

With this simple and useful application, we will be able to know the traffic passing through the network interfaces of our system. With this, we will be able to detect errors or know how much bandwidth is being consumed.

If there’s suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this. This makes it easy to identify programs that have gone wild and are suddenly taking up your bandwidth.

The application is cross-platform but most of the main features are only available for Linux. This is because NetHogs heavily relies on /proc.

Fortunately, it is an Open Source tool and because of this, we can take advantage of it in almost any situation.

So, let’s get to know it a bit. It is very flexible but also easy to use.

Install NetHogs on Linux

Before using the command, we have to install it on Linux. For this, we can either use the package from the official repositories or compile it ourselves from the source code.

In the case of Debian, Ubuntu, and derivatives, it is enough to run in a terminal

sudo apt update
sudo apt install nethogs

In the case of CentOS, RockyLinux, and AlmaLinux, we have to add the EPEL repository

sudo dnf install epel-release

And after that, we can install it using the following command

sudo dnf install nethogs

At the end of the installation process, you will be able to use the program without any problem.

Monitoring bandwidth on Linux with Nethogs

Using NetHogs we can monitor the traffic and bandwidth of network interfaces. You can also choose to monitor traffic on all interfaces (default behavior) or monitor traffic on a specific interface.

So, to monitor all the traffic on the system

sudo nethogs
NetHogs running
NetHogs running

This will bring up all traffic information for all network interfaces on the system. However, you can specify one in the following way

nethogs [interface]

For example

nethogs wlan0

In this case, only the selected interface will be monitored.

The monitoring will be continuous, but we will be able to use the -d option to add a refresh rate expressed in seconds.

sudo nethogs -d 5

In this way, every 5 seconds the monitoring and refreshing of the data will be performed.

Also, NetHogs has a traceroute mode that will display packets one by one. This can be activated with the -t option.

sudo nethogs -t

Once you run the command, you will have an interactive terminal.

Two useful options for displaying the data are the s and r options which sort the results by traffic sent and received respectively. All you have to do is press those keys and they will be executed.

A third very useful option is m which allows you to change the unit in which you express packets, which defaults to KB.

Monitoring the bandwidth in Linux with Nethogs
Monitoring the bandwidth in Linux with Nethogs

And to exit the shell type q.

So, enjoy it

Conclusion

NetHogs allows us to monitor the bandwidth of a network interface on the system. Besides this, it is quite useful for monitoring problems and high consumption.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook