Linux Tactic

Mastering Netstat SS and Fuser Commands in Linux

Navigating through Linux systems can be quite overwhelming, particularly for novice users. One of the primary features of Linux is its command-line interface, which can be daunting.

In this article, we’ll walk you through three methods that can be used to find port conflicts and process identifications (PID) using netstat, ss, and fuser commands. 1.

Finding Port Using PID in Linux

When multiple applications are connected to the internet, port conflicts may occur, resulting in connection issues. The first step in resolving these issues is to locate the cause of the conflict, which entails finding the process bound to the conflicting port.

Let’s take a look at some of the most widely used commands for locating the PID in Linux distributions. – Netstat command:

Netstat is a utility that provides information about the current status of the system’s network connections.

This command can detect active internet connections and reveal details about the processes running on a specific port. To use netstat command to find the port using PID in Linux, type the following command in your terminal window.

“`

$ sudo netstat -ltnp | grep

“`

The output will display the process (PID) associated with the specified port. “`

tcp6 0 0 :::80 :::* LISTEN 5129/httpd

“`

To interpret the PID (5129), enter the following command:

“`

$ ps aux | grep 5129

“`

This will display the entire command that is bound to the port.

– SS command:

The ss command is another option for locating PID using Linux. It is more efficient than netstat for monitoring traffic because it offers detailed information about a variety of network connections.

“`

$ sudo ss -ltnp port = :80

“`

The output will show you the PID of the process connected to the port. “`

State Recv-Q Send-Q Local Address:Port Peer Address:Port Process

tcp 0 0 0.0.0.0:80 0.0.0.0:* users:((“httpd”,PID=5129, fd=4),(“httpd”,PID=8842, fd=4))

“`

– Fuser command:

The fuser command is a Linux utility that is used to locate processes that are associated with the specified file or directory.

It’s also applicable to port numbers. “`

$ sudo fuser -v 80/tcp

“`

The output will show all processes currently bound to the port.

If no output is shown, it means that no process is currently associated with the port. 2.

Netstat command

Now that we’ve learned how to use netstat to locate the process using the port, let’s examine the netstat command in greater detail. This command provides a detailed summary of a system’s network connections, interface statistics, and routing tables.

If you want to display comprehensive information about network connections, netstat is the way to go. – Overview:

The netstat command is a utility that is included in most Unix-based operating systems.

This command can be used to monitor a variety of network activities, including networking statistics, network interface usage, and network protocols. Netstat is a useful tool for troubleshooting network problems, as it allows users to identify active network connections, ports, and the processes associated with those ports.

– Functionality:

The netstat command can provide a wide range of information about a system’s network connections. It can provide details about open sockets, active network connections, the number of bytes sent and received, and the various protocols currently running on the system.

This information can be used to identify potential security issues or performance bottlenecks and can help users diagnose connectivity problems. – Displaying PID:

Netstat can be used to display the PID of a particular process.

This is done by adding the “-p” option to the command. When this option is included, netstat will show the process identifier (PID) of each connection.

This information can be used to identify which process is associated with a particular network connection. “`

$ sudo netstat -tulpen

“`

The output for this command will display the following:

“`

tcp 0 0 127.0.0.1:3306 0.0.0.0:* mysql 12704 2740372 20 19:51 1m

tcp 0 0 127.0.0.1:587 0.0.0.0:* exim 1381 48735 4 19:00 28:54

tcp 0 0 0.0.0.0:80 0.0.0.0:* httpd 5129 599723 74 19:06 02:38

“`

In the fourth column of the output, you can see the PID of the process associated with each connection.

In conclusion, locating PID using Linux commands, such as netstat, ss, and fuser, is relatively straightforward. You can use any of these tools to locate processes that are associated with a specific port.

Additionally, the netstat command can also provide detailed information on network connections, interface statistics, and routing tables. It is a powerful tool that is essential for troubleshooting network problems and identifying potential security issues.

With the knowledge gained from this article, you’re now better equipped to troubleshoot and resolve networking issues on your Linux systems. 3.

SS Command

While netstat has been a reliable network utility tool for many years, it is an aging technology. As part of efforts to modernize Linux utilities, the ss command was developed by the same team that created netstat.

– Overview:

SS, short for Socket Statistics, is another Linux command-line utility that can be used to provide detailed information about a system’s network connection history, similar to netstat. This tool displays useful information such as open sockets, established connections and listening ports, enabling users to identify potential issues that may affect network performance and security.

– Modern Replacement for Netstat:

SS is recognized as the modern replacement for netstat. While netstat is still included in many Linux distributions and is still valuable, the ss command provides data in a clearer and more concise format.

The command is also capable of systematically providing information on IPv6, TCP, and IPSec protocols, making it more efficient in terms of gathering data. – Filtering Output:

Like other Linux commands, ss provides users with options to filter the output and display only what is necessary.

For instance, to show connections established on a specific port, we can filter the output using the following command:

“`

$ sudo ss -tlnp | grep :8080

“`

This will only display the network connections established on port 8080. 4.

Fuser Command

The fuser command is a Linux utility that displays the processes using a file system or a socket. It shows whether the file is locked, mounted, or busy and can also provide the user with the process identification number (PID).

This tool is primarily used to deal with issues related to systems resources or file access. – Overview:

Fuser is included in most Unix-based operating systems, like the ss and netstat commands.

It provides users with a simple method for determining which process owns any files, sockets, or directories. Like other Linux programs mentioned, administrators typically use it to troubleshoot and resolve issues with system resources and file access.

– Functionality:

The fuser command can display the process identification number (PID) of processes using a certain file or socket. This is helpful when troubleshooting issues related to resource allocation.

For instance, running the following command will display the process(es) associated with a particular file:

“`

$ sudo fuser /var/log/syslog

“`

The output will display the processes tied to the file. “`

/var/log/syslog: 1629 2675 3570

“`

The results show that there are three processes using the syslog file.

Moreover, administrators can choose to kill all these signals by doing the following:

“`

$ sudo fuser -k /var/log/syslog

“`

This commmand will send the kill signal to the process(es) associated with the syslog file. – Installation:

The fuser command is installed by default in most Linux-based systems.

However, if it’s not available, you can easily install it using package managers like apt-get (Ubuntu/Debian) and yum (CentOS/RHEL) :

For Ubuntu/Debian based systems:

“`

$ sudo apt-get install psmisc

“`

For CentOS/RHEL based systems:

“`

$ sudo yum install psmisc

“`

In conclusion, as an administrator or a Linux user, it’s important to be familiar with the troubleshooting tools that are available. Three essential utilities are netstat, ss, and fuser commands.

Netstat is used to provide information on network connections, interface statistics, and routing tables. SS provides a modern replacement for netstat, which offers a more concise format.

It presents valuable information on open sockets, established connections, and listening ports. Fuser displays processes that are associated with files or sockets and is great for troubleshooting problems related to limited resources and access issues.

As always, a better knowledge of these Linux commands will improve your ability to diagnose and fix various network issues. 5.

Conclusion

In this article, we have discussed three network commands that are essential for Linux administrators and users. Netstat, SS, and fuser commands are widely used to identify network performance issues, resource utilization, and troubleshooting.

Let’s take a closer look at how these commands can be compared and evaluated, and which one is the classic and all-time best command. – Three Different Commands:

Netstat, SS, and fuser are all different tools that are designed to provide information about network connections.

Netstat has been around for decades, while SS and fuser commands were developed in recent years. While these commands differ in their output and capabilities, they all serve the same purpose.

– Comparison between Netstat and SS:

Netstat and SS provide similar information, but the output format and options for the two commands differ. SS is considered the preferred alternative to netstat because it provides more comprehensive information about network connections.

SS is more efficient than netstat when looking for specific information, and with the increased use of IPv6 protocol, it can reveal information that may be lost in netstat. – Classic and All-Time Best Command:

Netstat is often considered as a classic command that has withstood the test of time.

It has been used for decades and is a reliable tool for monitoring network connections, interface statistics, routing tables, and more. Even with the availability of SS command, netstat is still valuable as it is installed in most Linux distributions.

While newer commands such as SS have more advancements, netstat remains an essential utility tool for network administrators. In conclusion, knowledge of netstat, SS, and fuser command will improve your ability to monitor and analyze network connections, identify performance issues and diagnose access problems.

While netstat remains the classic and the all-time best command, SS has evolved into a preferred alternative. Additionally, fuser command can be used to identify which processes are using a specific file or directory, and diagnose various file access issues.

Familiarizing yourself with these tools is essential for debugging networking and system issues in a Linux environment. In conclusion, understanding and utilizing commands such as netstat, ss, and fuser in Linux is crucial for network administrators and users.

These tools offer valuable insights into network connections, resource utilization, and troubleshooting in a Linux environment. While netstat remains a classic and reliable command, ss provides a more modern and efficient alternative.

Fuser enables users to identify processes associated with files and sockets, aiding in diagnosing access problems. By familiarizing ourselves with these commands, we gain the ability to diagnose and resolve network issues effectively.

So, whether you’re a Linux administrator or an enthusiastic user, mastering these commands will greatly enhance your ability to navigate and troubleshoot in a Linux system.

Popular Posts