To troubleshoot network connectivity or application issues, you need to check which ports the system is using and which applications are listening on that particular port.

In this article, we will see different Linux commands to check the open ports in Linux to troubleshoot the issue.

1) Use "netstat" command to check if the port is open in Linux

The netstat command is part of the net-tools package, which is not included in the Linux distribution by default. It displays network-related data such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships, and so on. On Ubuntu, you can use the following command to install the net-tools package.

# apt update -y && apt install net-tools -y

To list all TCP or UDP ports used by the system, including the service using the port and the socket status, use the following command.

# netstat -tunlp

-t -> It shows the TCP ports.
-u -> It displays the UDP ports.
-n -> It shows the numerical addresses instead of resolving hosts.
-l -> It displays only the listening ports.
-p -> It shows the PID and the listener's process name.

Below is the description of the important columns that you should know.

Proto: The protocol that the socket uses.
Local Address: It shows the IP address and port number the process listens to.
PID/Program name: It shows the PID and process name.

2) Use "ss" command to check if the port is open in Linux

The ss command is another command-line utility for checking open ports. It shows socket statistics that are used to check if a port is open. The ss command shows more information about open ports than other tools.

Enter the following command to get a list of all listening ports with ss:

# ss -tunlp

3) Use "lsof" command to check if the port is open in Linux

The lsof command is another helpful tool for checking open ports. The lsof stands for list open files and displays information about open files on your system. This information includes file descriptors, process IDs, user IDs, and so on.

To get a list of all TCP ports that are listening, use the lsof command in the terminal.

# sudo lsof -nP -iTCP -sTCP:LISTEN

The options used are as follows:
-n -> It lists the entry that does not convert the port number to the port name.
-p -> It shows the entry that does not resolve the hostname and shows numerical addresses.
-iTCP -sTCP:LISTEN -> It shows only network files with TCP state LISTEN.

Conclusion:

Checking listening ports on a Linux system isn't just for debugging—it's essential for security, performance tuning, and overall system health. Tools like netstat, ss, and lsof give you a complete view of active connections, which services are using which ports, and whether anything unexpected is lurking on your system. Each command has its own strengths, and knowing how to use them makes you a sharper, more effective Linux operator. Whether you're locking down your firewall or hunting for rogue processes, this is foundational knowledge every Linux admin should have in their toolbox.

Was this answer helpful? 0 Users Found This Useful (0 Votes)