How To Install Nethogs on Rocky Linux 9
In today’s interconnected world, monitoring network traffic has become an essential task for system administrators and power users. When managing servers or troubleshooting network issues, having the right tools to identify which processes are consuming bandwidth can make a significant difference in maintaining optimal system performance. Nethogs stands out as a powerful utility that provides real-time insights into network bandwidth usage on a per-process basis, unlike other tools that display information by protocol or subnet.
Rocky Linux 9, as a stable and enterprise-ready distribution, has become increasingly popular for server deployments. Whether you’re managing a busy web server, database server, or simply want to monitor network activity on your workstation, installing Nethogs on Rocky Linux 9 can help you maintain control over your network resources.
This comprehensive guide will walk you through the entire process of installing and configuring Nethogs on Rocky Linux 9, from preparing your system to advanced usage techniques. By the end of this tutorial, you’ll have a powerful network monitoring tool at your disposal to help identify bandwidth-intensive applications and optimize your network performance.
Understanding Nethogs and Its Importance
Nethogs is a small yet powerful utility that breaks down network traffic by process rather than by protocol or subnet. This unique approach makes it an invaluable tool for network troubleshooting and optimization. Unlike traditional network monitoring tools that focus on protocols or ports, Nethogs focuses on the actual processes using your network, allowing you to quickly identify which applications are consuming the most bandwidth.
Nethogs provides several key features that make it an essential addition to any system administrator’s toolkit:
- Real-time monitoring of network usage on a per-process basis
- Process-specific bandwidth tracking that clearly shows which applications are using your network
- Support for both IPv4 and IPv6 connections for comprehensive monitoring
- Minimal system resource consumption ensuring it won’t slow down your system
- A straightforward command-line interface that’s easy to use yet powerful
The ability to group bandwidth utilization by process instead of protocol gives you unprecedented insight into your system’s network activity. For instance, when troubleshooting unexpected network slowdowns, Nethogs can immediately show which process is responsible, saving valuable time in identifying and resolving issues.
Whether you’re managing server infrastructure, developing network-intensive applications, or simply curious about your system’s network usage, Nethogs provides the visibility needed to make informed decisions about network resource allocation and optimization.
Prerequisites for Installing Nethogs
Before proceeding with the installation of Nethogs on Rocky Linux 9, ensure that your system meets the following requirements:
- A server or workstation running Rocky Linux 9
- Root or sudo privileges on your account
- An active internet connection for downloading packages
- Basic familiarity with Linux terminal commands
- Properly configured network interfaces
It’s always good practice to update your system before installing new software. This ensures you have the latest security patches and dependencies. Open a terminal and run the following commands:
sudo dnf update -y
sudo dnf upgrade -y
These commands will refresh your package repositories and upgrade any packages that need updating. The `-y` flag automatically answers “yes” to any prompts, making the process non-interactive.
Additionally, you may need some development tools and libraries if you plan to compile Nethogs from source code. While we’ll cover the repository installation method first, having these tools ready can be useful:
sudo dnf groupinstall "Development Tools" -y
sudo dnf install ncurses-devel libpcap-devel -y
Finally, verify that your network connection is functioning correctly. A simple ping test can confirm your connectivity:
ping -c 4 google.com
If the ping command returns responses without errors, your network connection is working properly and you’re ready to proceed with the installation.
Preparing Your Rocky Linux 9 System
Proper preparation is essential before installing any software on your Rocky Linux 9 system. This ensures a smooth installation process and prevents potential issues down the line. Let’s get your system ready for Nethogs installation.
Updating Package Repositories
First, make sure your system’s package repositories are up to date. This step is crucial as it ensures you have access to the latest versions of packages and their dependencies:
sudo dnf update -y
Configuring Repositories
Rocky Linux 9, like other RHEL-based distributions, uses the DNF package manager. By default, Nethogs is not available in the standard Rocky Linux repositories. To install it, you’ll need to enable the EPEL (Extra Packages for Enterprise Linux) repository, which contains additional packages not included in the base repositories.
To enable the EPEL repository, run the following command:
sudo dnf install epel-release -y
This command installs the package that configures your system to use the EPEL repository. After running this command, verify that the repository has been added successfully:
sudo dnf repolist
The output should include an entry for the EPEL repository. If it doesn’t appear, try running the update command again:
sudo dnf update -y
Testing Repository Access
Before proceeding with the installation, it’s a good idea to verify that your system can access the EPEL repository properly:
sudo dnf repository-packages epel list
This command lists all available packages from the EPEL repository. If you see a lengthy list of packages, your repository configuration is working correctly.
Network Configuration Check
Since Nethogs is a network monitoring tool, it’s important to ensure your network interfaces are properly configured. You can check your current network configuration with:
ip addr show
Make note of your network interface names (such as eth0, ens192, or enp0s3), as you’ll need this information when using Nethogs to monitor specific interfaces. If you notice any issues with your network configuration, you might need to resolve them first before proceeding.
With these preparation steps completed, your Rocky Linux 9 system is now ready for the installation of Nethogs.
Step-by-Step Installation of Nethogs
Now that your system is properly prepared, let’s proceed with the installation of Nethogs on Rocky Linux 9. The process is straightforward and can be completed in just a few steps.
Installing Nethogs from EPEL Repository
With the EPEL repository enabled, installing Nethogs is as simple as running a single command:
sudo dnf install nethogs -y
DNF will automatically resolve and install all required dependencies. The installation should complete quickly, as Nethogs is a lightweight utility.
Verifying the Installation
After the installation completes, verify that Nethogs was installed correctly by checking its version:
nethogs -V
This command should display the version of Nethogs installed on your system. If you see something like “nethogs version 0.8.6” or similar, the installation was successful.
Manual Installation from Source (Alternative Method)
If you prefer to install the latest version of Nethogs directly from the source code, or if the repository version is outdated, you can compile it yourself. Here’s how:
1. First, install the required dependencies:
sudo dnf groupinstall "Development Tools" -y
sudo dnf install ncurses-devel libpcap-devel -y
2. Clone the Nethogs repository from GitHub:
git clone https://github.com/raboof/nethogs
3. Navigate to the Nethogs directory:
cd nethogs
4. Compile and install Nethogs:
make
sudo make install
5. Verify the installation:
nethogs -V
This method gives you access to the latest features and improvements that might not yet be available in the repository version.
Post-Installation Configuration
Unlike some other tools, Nethogs doesn’t require extensive configuration after installation. It works out of the box, but you might want to set up some aliases for convenience.
You can add an alias to your `.bashrc` or `.bash_profile` file to make running Nethogs easier:
echo "alias nh='sudo nethogs'" >> ~/.bashrc
source ~/.bashrc
This creates a shortcut command `nh` that runs Nethogs with sudo privileges, saving you some typing in the future.
With Nethogs now successfully installed on your Rocky Linux 9 system, you’re ready to start monitoring your network traffic on a per-process basis.
Basic Usage of Nethogs
Now that Nethogs is installed on your Rocky Linux 9 system, let’s explore its basic usage to monitor network traffic. As a process-specific network monitoring tool, Nethogs provides valuable insights into which programs are using your bandwidth.
Starting Nethogs with Default Settings
To start Nethogs with the default settings, simply run the command with sudo privileges:
sudo nethogs
This command launches Nethogs and automatically monitors all available network interfaces. The display shows a real-time list of processes using your network, sorted by bandwidth usage.
Understanding the Nethogs Interface
When you run Nethogs, you’ll see a display similar to the following:
NetHogs version 0.8.6
PID USER PROGRAM DEV SENT RECEIVED
1234 user1 /usr/bin/firefox eth0 2.1KB/s 20.2KB/s
2345 user2 /usr/lib/slack eth0 1.2KB/s 1.1KB/s
3456 user1 /usr/bin/dropbox eth0 0.1KB/s 0.7KB/s
TOTAL 3.4KB/s 22.0KB/s
In this display:
- PID: Process ID of the program using the network
- USER: Username running the process
- PROGRAM: Path to the application or process responsible for network activity
- DEV: Network device being used
- SENT: Current upload speed of that process
- RECEIVED: Current download speed of that process
The bottom row shows the total bandwidth being used across all processes.
Keyboard Shortcuts for Navigation
While Nethogs is running, you can use several keyboard shortcuts to control the display:
- m: Switch between different units (KB/s, KB, B, MB)
- r: Sort by received traffic
- s: Sort by sent traffic
- q or Ctrl + C: Quit Nethogs
These shortcuts make it easy to navigate and analyze the information provided by Nethogs.
Monitoring Specific Network Interfaces
If you want to monitor a specific network interface rather than all interfaces, specify it as an argument:
sudo nethogs eth0
Replace `eth0` with your actual interface name, which might be something like `ens192` or `enp0s3` depending on your system configuration. You can list all available interfaces using the `ip addr` command.
Setting the Refresh Rate
By default, Nethogs updates its display every second. You can change this refresh rate using the `-d` option followed by the number of seconds:
sudo nethogs -d 5
This command sets Nethogs to update the display every 5 seconds, which can be useful for monitoring over longer periods with less frequent updates.
With these basic commands and options, you can start using Nethogs effectively to monitor your network traffic. In the next section, we’ll explore more advanced configuration options to tailor Nethogs to your specific needs.
Advanced Configuration and Usage
Once you’re comfortable with the basic functionality of Nethogs, you can explore its advanced features to get more out of this powerful network monitoring tool.
Customizing the Display Units
By default, Nethogs displays traffic in KB/s (kilobytes per second). However, you can change the display units using the command-line options:
sudo nethogs -K
The `-K` option forces Nethogs to display traffic in KB/s. You can also use the `m` key while the program is running to cycle through different units: KB/s, total KB, total B, and total MB.
Monitoring Multiple Interfaces
You can monitor multiple specific interfaces by listing them after the nethogs command:
sudo nethogs eth0 wlan0
This is particularly useful for systems with multiple network connections where you want to monitor traffic across specific interfaces.
Setting Custom Refresh Intervals
For more precise control over how often Nethogs updates its display, use the `-d` option followed by a decimal value:
sudo nethogs -d 0.5
This sets Nethogs to update every half-second, providing more real-time information. However, keep in mind that very frequent updates might increase CPU usage.
Tracing Mode
Nethogs offers a tracing mode that outputs the current bandwidth usage to stdout:
sudo nethogs -t
This mode is particularly useful for scripting or logging network usage over time. The output can be redirected to a file for later analysis:
sudo nethogs -t > network_log.txt
Filtering Traffic
While Nethogs doesn’t have built-in filtering capabilities like some other tools, you can combine it with other Linux commands to filter its output. For example, to monitor only processes owned by a specific user:
sudo nethogs | grep username
Creating Custom Scripts
For more advanced monitoring, you can create custom scripts that leverage Nethogs’ output. For example, a simple script to alert you when a process exceeds a certain bandwidth threshold:
#!/bin/bash
sudo nethogs -t | while read line; do
if [[ $line == *"firefox"* ]]; then
received=$(echo $line | awk '{print $3}')
if (( $(echo "$received > 1000" | bc -l) )); then
echo "Firefox is using more than 1000 KB/s: $received KB/s"
# Add notification command here
fi
fi
done
Save this script with a `.sh` extension, make it executable with `chmod +x script.sh`, and run it to monitor Firefox’s bandwidth usage.
Integration with System Monitoring
For comprehensive system monitoring, you can integrate Nethogs with other monitoring tools. For instance, you might set up a cron job to periodically run Nethogs and log the results, then process these logs with tools like Grafana or Prometheus for visualization.
These advanced configurations allow you to tailor Nethogs to your specific network monitoring needs, making it an even more powerful tool in your Linux administration toolkit.
Practical Use Cases and Examples
Nethogs is a versatile tool that can be applied in various scenarios to help manage and optimize network usage. Let’s explore some practical use cases and examples to demonstrate its value in real-world situations.
Identifying Bandwidth-Intensive Applications
One of the most common uses for Nethogs is identifying which applications are consuming excessive bandwidth. For instance, you might notice your server’s network performance is degrading but aren’t sure which process is responsible. Running Nethogs will immediately show you the culprit:
sudo nethogs
This command might reveal that a backup process, web server, or database replication is using more bandwidth than expected, allowing you to take appropriate action.
Troubleshooting Network Bottlenecks
When users report slow network performance, Nethogs can help pinpoint the source of the problem:
sudo nethogs -d 1
By monitoring network usage in real-time with a 1-second refresh rate, you can quickly identify if a particular application is causing a network bottleneck and take immediate steps to address it.
Detecting Unusual Network Activity
Unexpected network activity could indicate security issues such as malware or unauthorized access. Nethogs helps you spot unusual patterns:
sudo nethogs eth0
If you see unknown processes using significant bandwidth, it may warrant further investigation for potential security breaches.
Optimizing Application Performance
For developers, Nethogs provides valuable insights into how applications use network resources:
sudo nethogs | grep myapp
This helps in identifying inefficient network operations in your applications, allowing you to optimize code for better performance and reduced bandwidth consumption.
Monitoring Remote Server Activity
When administering remote servers, understanding network usage patterns is crucial:
ssh user@server "sudo nethogs -t" > server_network_log.txt
This command remotely runs Nethogs in tracing mode and saves the output locally, enabling you to analyze network patterns without staying connected to the server.
Resource Planning and Capacity Management
Nethogs can help in making informed decisions about resource allocation and capacity planning:
sudo nethogs -t | awk '{sum+=$3} END {print sum/NR " KB/s average"}'
This command calculates the average bandwidth usage, which is useful for determining if you need to increase your network capacity or implement bandwidth management policies.
These practical examples demonstrate how Nethogs can be an essential tool for system administrators and developers in managing network resources effectively. By providing process-specific network usage information, Nethogs enables more targeted and efficient troubleshooting and optimization.
Performance Considerations
When using Nethogs on Rocky Linux 9, it’s important to understand its impact on system resources and how to optimize its performance. Nethogs is designed to be lightweight, but like any monitoring tool, it does consume some system resources.
System Resource Impact
Nethogs generally has a minimal impact on system performance. It typically uses less than 1% of CPU and a small amount of memory on modern systems. However, the resource usage can vary depending on:
- The number of active network connections
- The refresh rate you’ve configured
- The overall system load
On busy servers with thousands of connections, Nethogs might use slightly more resources, but it’s still designed to be efficient.
Optimizing Resource Usage
To minimize Nethogs’ resource consumption, consider these optimization strategies:
1. Use a longer refresh interval for continuous monitoring:
sudo nethogs -d 5
This updates the display every 5 seconds instead of the default 1 second, reducing CPU usage.
2. Monitor specific interfaces instead of all interfaces:
sudo nethogs eth0
This focuses the monitoring effort on only the relevant network traffic.
3. Run Nethogs only when needed rather than continuously, especially on production servers with limited resources.
Comparison with Other Monitoring Tools
Compared to other network monitoring tools, Nethogs offers a good balance between functionality and resource usage:
- iftop: Similar resource usage but shows connections rather than processes
- nload: Lighter than Nethogs but provides only interface-level statistics
- wireshark: Much heavier resource usage but offers deeper packet analysis
- tcpdump: Lighter for capturing traffic but provides raw data that needs further processing
Nethogs’ focus on per-process monitoring makes it uniquely valuable despite alternatives that might use slightly fewer resources.
Long-term Monitoring Considerations
For long-term monitoring, consider these strategies:
1. Use the tracing mode and log to a file periodically rather than running the interactive mode continuously:
sudo nethogs -t > nethogs_log.txt
2. Implement log rotation to prevent log files from growing too large:
sudo nethogs -t | rotatelogs -n 5 nethogs_log.txt 86400
3. Consider setting up scheduled monitoring during peak hours rather than 24/7 monitoring if resources are constrained.
By being mindful of these performance considerations, you can effectively use Nethogs for network monitoring on Rocky Linux 9 without significantly impacting your system’s performance. The tool’s efficient design makes it suitable for both periodic troubleshooting and ongoing monitoring tasks.
Troubleshooting Common Issues
Even with careful installation and configuration, you might encounter some issues when using Nethogs on Rocky Linux 9. This section addresses common problems and their solutions to help you get the most out of this network monitoring tool.
Permission-Related Problems
Issue: You receive a “Permission denied” error when trying to run Nethogs.
Solution: Nethogs requires root privileges to access network interface information. Always run it with sudo:
sudo nethogs
If you’re still encountering permission issues, verify that your user has sudo privileges:
sudo -l
Interface Recognition Problems
Issue: Nethogs doesn’t recognize or shows incorrect network interfaces.
Solution: First, list all available network interfaces:
ip addr show
Then specify the correct interface when running Nethogs:
sudo nethogs eth0
Replace `eth0` with your actual interface name. If Nethogs still doesn’t recognize the interface, verify that the interface is up and has an IP address assigned.
Missing Dependencies
Issue: Installation fails due to missing dependencies.
Solution: Ensure all dependencies are installed:
sudo dnf install libpcap-devel ncurses-devel
If you’re installing from source, make sure you have the development tools:
sudo dnf groupinstall "Development Tools"
Display or Interface Issues
Issue: Nethogs displays garbled text or doesn’t fit properly in your terminal.
Solution: Resize your terminal window or adjust the refresh rate:
sudo nethogs -d 2
For text encoding issues, check your terminal’s character encoding settings and ensure it supports UTF-8.
No Network Activity Shown
Issue: Nethogs runs but doesn’t show any network activity.
Solution: First, verify that there is actual network traffic:
ping -c 4 google.com
If there is traffic but Nethogs doesn’t show it, try running Nethogs with all interfaces:
sudo nethogs
You might also need to check firewall rules that could be affecting Nethogs’ ability to monitor traffic:
sudo firewall-cmd --list-all
Crashes or Unexpected Behavior
Issue: Nethogs crashes or behaves unexpectedly.
Solution: Check the system logs for clues:
journalctl -xe | grep nethogs
Consider reinstalling Nethogs or trying a different version:
sudo dnf reinstall nethogs
Or compile the latest version from source as described in the alternative installation section.
High CPU Usage
Issue: Nethogs consumes excessive CPU resources.
Solution: Increase the refresh interval:
sudo nethogs -d 5
Or limit monitoring to specific interfaces that are most relevant to your needs.
By addressing these common issues, you can ensure a smooth experience with Nethogs on your Rocky Linux 9 system. Most problems have straightforward solutions that allow you to get back to effective network monitoring quickly.
Congratulations! You have successfully installed Nethogs. Thanks for using this tutorial for installing the Nethogs on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Ionic Nethogs website.