It is important to check network-related issues, especially during network troubleshooting. The first thing to check is which ports are active and listening or which application is connected to your server. The listening port portion of a network indicates which process is listening and serves as the communication endpoint. The state of the listening port can be open, closed, filtered or unfiltered.
Follow the guidance of this article if you are looking 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 Linux system. Let’s check these out practically:
- 1: Listening ports via netstat command
- 2: Listening ports via ss command
- 3: Listening ports via the lsof command
- 4: Listening ports via the 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. Using the netstat command on a Linux system will give you complete information about TCP, UDP, incoming and outgoing connections, multicast memberships, routing tables and port listening.
Run the mentioned command to list all ports with netstat command:
The above flags describe the following:
t – for TCP ports
u – for UDP ports
n – for numeric addresses
l – to show listening ports
p – to display PIDs
2: Listening ports via ss command
Socket Statistics (ss) is another way to print out network socket information with additional details and statistics. It’s a great alternative to the netstat command with some similar features.
You can run the given command to listen on ports on Linux:
3: Listening ports via the lsof command
As we know, everything in Linux and UNIX works as a file system. Whether it’s a device or a 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 open files.
We can run the following command to list network files and port listening information on a Linux system:
4: Listening ports via the nmap command
The Network Mapper (nmap) is one of the most secure auditing tools for displaying network information. It is used by network professionals for network discovery and listening ports.
The nmap is not a built-in tool in the Linux system, it can be installed with the following command in the terminal:
The following command would be used to show all open and listening ports of the Linux system:
Listening ports are network ports on which the application or process is listening, or we can say these are the communication endpoints. It is important that you keep an eye on network issues and the applications connected to our network server. In the guidelines above, we covered various ways to view our Linux system’s listening ports. We did it with command line tools ie netstat, ss, nmap and lsof.