How Do You Determine the Port Number That a Web Service Is Listening On?

Problem scenario
You have access to the backend of a Linux server.  You want to know if a port is in use (e.g., if there is activity on it).  You believe that an active service is listening an a TCP port.  How do you determine the port number of that service?

To be diligent, do these three things:

1.  Run this command to find a list of listening services:
sudo netstat -anlp | grep -i listen

The output may be associated with a specific service, process or application that is visible in the output of the netstat command above.  You may exhaustively try the different ports if you construct sockets in a web browser (e.g., x.x.x.x:123 to test port 123 where x.x.x.x is the external IP address of the server).

2.  If you have the nmap utility installed, you run this command to find similar results:

nmap -p1-65535 | grep open

3.Run these two commands:
lsof -i

Leave a comment

Your email address will not be published. Required fields are marked *