Find out what process is listening on a particular port on a Linux server

I was recently trying to debug an app that had gone rouge on a server because of a PHP upgrade. It was a web based application listening on a particular port and after the upgrade it just returned 500 server errors. A quick scan of the Apache logs, and even a deeper grep of them returned no matching errors so I realized, although the application was using PHP it was using another process to serve the pages. The urls of the application had the port 8443, so I knew whatever was serving it up was listening on that port.

Enter netstat

By default netstat tries to give you a human readable list of services. But with the -n flag you can see the numeric ports. You’ll also need to add -l (show listening ports) or -a (show all ports) since the listening ports are not included by default. -p will include the process id and the “program” that is listening which is what we really want. Grep is a nice way to narrow things down after that…

1
2
3
$ netstat -nlp | grep 8443
tcp        0      0 0.0.0.0:8443          0.0.0.0:*
           LISTEN      1234/lighttpd
Category(s): Command Line, grep, Server Administration, Web Servers
Tags: , , , , , , ,

Leave a Reply

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

*

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free