Linux List The Open Ports And The Process That Owns Them

by on May 30, 2008 · 11 comments· LAST UPDATED June 25, 2012

in , ,

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):

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 11 comments… read them below or add one }

1 Jeff Schroeder May 30, 2008 at 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


2 Mark Nixon May 30, 2008 at 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.


3 harsha gowda July 10, 2008 at 11:36 am



4 alojamento de sites July 22, 2010 at 12:29 pm

Very useful, thanks


5 paul March 31, 2011 at 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.


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

@paul: did you run the commands as root?


7 paul March 31, 2011 at 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?


8 Mark Nett January 5, 2012 at 11:51 am

Running sudo lsof -i gives me command not found?


9 Sarjeet Singh August 13, 2013 at 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.


10 sob March 28, 2012 at 12:33 pm



11 Jim Aman February 28, 2013 at 7:59 pm

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


Leave a Comment

Tagged as: , , , , , ,

Previous post:

Next post: