How to monitor network usage for Linux processes
Luckily, with some popular Linux utilities, it's easy to monitor which processes are using your bandwidth. Here are some of those tools.
1. nethogs
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
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
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
You should read it
- How does the Linux Kernel work?
- How to use Conky to make Linux more awesome
- How to monitor, clean and optimize Linux with Stacer
- How to monitor network connections in Linux with pktstat
- History of Linux operating system, a strange development path
- How to debug a Windows application with Process Monitor
- What is Linux Hosting?
- Use the Top command to see the processes running in Linux
May be interested
- Instructions for using pstree command on Linuxpstree is a powerful and useful command to display processes running in linux. like the ps command, it shows all the processes that are currently active on your login system. the main difference is that when running the pstree command, processes are organized into tree sorting instead of lists like using the ps command.
- Data analysis with Network Monitorfor a network administrator, a very important operation is to control the traffic that runs on your network. however, because the number of packets on the network is very large, it is almost impossible to track the contents of each package. network administrators can only monitor the different types of protocols that are sending and receiving packets on the network. the job
- How to run a program periodically using the Watch command on Linuxusing the watch command, you can monitor real-time system activities such as user login information, network status, memory and cpu usage, disk space, etc.
- 7 extremely interesting Wifi features on Windows 10 not everyone knowsautomatically re-enable wifi after a specific time, monitor data usage or block specific networks from appearing ... are some useful wifi tips on windows 10 that many users do not know.
- How to monitor, clean and optimize Linux with Stacerlooking for ways to optimize your linux system and make it run faster? there are tons of ways and tools for you to do this, and stacer includes everything you need to monitor, clean, and optimize your linux installation.
- Learn about the management and monitoring functions of Resource Monitor toolin the following article, we will show you some of the features and usage of the handy resource monitor tool from microsoft, which is used to manage and monitor the operation of the network system. storage capacity and system performance ...
- Top 10 best bandwidth monitoring softwaremonitoring network bandwidth is very important. it helps users understand what's going on within their network.
- How to use SysGauge to monitor 'health' Windows computerssysgauge is a free software that monitors windows computer health, checks cpu usage, network transfer speed, operating system performance, etc.
- Autrace - Tool to check, count and monitor Linux processesmany people still do not know what autrace is? the information you need to know about autrace will be shared by tipsmake in the article below.
- The du (Disk Usage) commands are most handy in Linuxdu is a command line tool provided with linux, which reports the amount of disk space used by directories and files. du stands for 'disk usage'.