≡ Menu

Linux List The Open Ports And The Process That Owns Them

So how do you list the network open ports on your Linux server and the process that owns them? The answer is simple. Use the following command (must be run as the root user):

sudo lsof -i
sudo netstat -lptu
sudo netstat -tulpn

Sample outputs (see video demo):

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 12 comments… add one }

  • Jeff Schroeder May 30, 2008, 12:50 pm

    Shameless plug to a really good article I wrote about lsof and some of the more nifty tricks:

    Troubleshooting running systems with lsof

    • Ankita Nautiyal April 21, 2015, 6:24 am


      We recently did patching in our linux servers and want to know which process is using which patch. Do we have any linux command to know that.

      Thanks in advance

  • Mark Nixon May 30, 2008, 6:42 pm

    Thanks Vikrant for the useful tip…I’ve used lsof for ages but sort of taken it for granted,didn’t check the man pages, and wasn’t aware of this option.

    Great (!!!) site, by the way, I’ll start contributing my own tips as well. Thanks for giving me lots of ideas-projects to increase my understanding of Linux/BSD.

  • harsha gowda July 10, 2008, 11:36 am


  • alojamento de sites July 22, 2010, 12:29 pm

    Very useful, thanks

  • paul March 31, 2011, 3:08 am

    What should I do when netstat lists the PID as “-” and lsof doesn’t list anything for that port? I know something is listening on that port because “nc -z -v -w1 1-65534” says so.

  • Jeff Schroeder March 31, 2011, 6:35 am

    @paul: did you run the commands as root?

  • paul March 31, 2011, 5:45 pm


    Thanks for the reply! Yes, I did run all the commands as root. I ran nc from both a different machine on the network and also the same machine that has the port open.

    Any ideas?

  • Mark Nett January 5, 2012, 11:51 am

    Running sudo lsof -i gives me command not found?

    • Sarjeet Singh August 13, 2013, 11:38 pm

      Can you try “which lsof” and see if it tells the path. If it does, try using the full path and see if this works?

      If not, try installing using apt-get install lsof and try then.

  • sob March 28, 2012, 12:33 pm


  • Jim Aman February 28, 2013, 7:59 pm

    What music is played in the video “Linux List The Open Ports And The Process That Owns Them”

Leave a Comment