Share your love
Check Service Listening Port on Linux with 3 Easy Methods

In this guide from the Linux Tutorials, we want to teach you How To Check Service Listening Port on Linux. A port is an addressable network location implemented in an operating system to help differentiate traffic destined for different services or applications. A port is always associated with the IP address of a host and the protocol type used for communication.
A service is said to be “listening” on a port when it is binding to a port/protocol/IP address combination in order to wait for requests from clients of the service. Upon receipt of the request, a one-to-one server-client dialog using the same port number is established.
Table of Contents
Steps To Check What Service is Listening on a Specific Port on Linux
If you face these questions: How do I find out which service is listening on a specific port? And how do I find out what program is listening on a specific TCP Port? You can follow the steps below to get your answers.
Method 1. Check Service Listening Port on Linux with lsof command
lsof command stands for List Of Open Files. This command provides a list of files that are opened. It gives the information to find out which files are opened by which process.
To see IPv4 Service Listening Port, you can use the command below:
lsof -Pnl +M -i4
Example output:

To see IPv6 Service Listening Port, you can use the following command:
lsof -Pnl +M -i6
Example output:

As you can see, from the output, you will get information about which service is listening on a specific port.
For more information about the lsof command, you can use the command below:
man lsof
Method 2. Get Service Port Information with netstat command
At this point, you can use the netstat command to get information about the service port on Linux.
The netstat command, meaning network statistics, is a Command Prompt command used to display very detailed information about how your computer is communicating with other computers or network devices.
Specifically, it can show details about individual network connections, overall and protocol-specific networking statistics, and much more, all of which could help troubleshoot certain kinds of networking issues.
To do this, you can use the commands below:
# netstat -tulpn
Or
# netstat -npl
Example Output:

The last column, PID/Program name, gives information regarding the program name and port. At this point, to get more information about the netstat command, you can use the man page:
man netstat
Method 3. Use /etc/services File To Get Services Port
The /etc/services file is used by applications to translate human-readable service names into port numbers when connecting to a machine across a network. The file will typically include the service name, port/protocol, any aliases, and comments.
To do this, you can use the following commands:
$ cat /etc/services
$ grep 110 /etc/services
$ less /etc/services
Example Output:

Conclusion
At this point, you have learned to check or Find What Service or Program is Listening on a Specific TCP Port on Linux. Checking service listening ports on Linux helps ensure that required services are running and accessible while identifying potential security risks. It also helps troubleshoot network issues and manage firewall settings.
Hope you enjoy it. Please subscribe to us on Facebook and YouTube.
Also, you may also like these guides:
Open and Close Ports with FirewallD on Rocky Linux 8