It is important to keep a check on network-related issues specifically while doing network troubleshooting. The first thing that needs to be checked is which ports are active and listening or what application is connected to your server. The listening port section on a network tells which process listens and serves as a communication endpoint. The state of the listening port can be opened, closed, filtered, or unfiltered.
Follow this article’s guide, if you are searching for commands to check listening port information on Linux.
How to Check Listening Ports on Linux
There are four easy and quick ways to get listening port information on the Linux system. Let’s check these practically:
- 1: Listening Ports via Netstat Command
- 2: Listening Ports via ss Command
- 3: Listening Ports via lsof Command
- 4: Listening Ports via nmap Command
1: Listening Ports via Netstat Command
Network Statistics (netstat) is a command-line network monitoring and troubleshooting tool. It is used to manage the configuration of connections over the network. While using the netstat command on a Linux system, you would get complete information about TCP, UDP, incoming and outgoing connections, multicast memberships, routing tables, and port listening.
Run the mentioned command to list all ports using the netstat command:
The above flags describe the following:
t – for TCP ports
u – for UDP ports
n – for numerical addresses
l – to display listening ports
p – to display PIDs
2: Listening Ports via ss Command
The socket statistics (ss) is another way to print network socket information with additional details and statistics. It is a great alternative to netstat command with some similar functions.
You can execute the given command to listen ports on Linux:
3: Listening Ports via lsof Command
As we know, everything in Linux and UNIX works as a filesystem. Whether it is a device or folder, you can call it a file. Some of these files are visible and some are hidden from us. The lsof (list of open files) command is a built-in command line tool used to display information about opened files.
We can execute the following command to list network files and port listening information on a Linux system:
4: Listening Ports via nmap Command
The Network Mapper (nmap) is one of the most secure auditing tools to display network information. It is used by network experts for network discovery and listening ports.
The nmap is not a built-in tool in the Linux system, it can be installed using the following command in the terminal:
The following command would be used to display all open and listening ports of the Linux system:
Conclusion
Listening ports are network ports on which the application or process listens on, or we can say that these are the communication endpoints. It is important for you to keep a check on network issues and what applications are connected to our network server. In the above guidelines, we have covered different ways to display the listening ports of our Linux system. We did it using command-line tools i-e, netstat, ss, nmap and lsof.