Linux List The Open Ports And The Process That Owns Them

by on May 30, 2008 · 10 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):



If you would like to be kept up to date with our posts, you can follow us on Twitter, Facebook, Google+, or even by subscribing to our RSS Feed.


{ 10 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

Reply

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.

Reply

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

Thanks

Reply

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

Very useful, thanks

Reply

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.

Reply

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

@paul: did you run the commands as root?

Reply

7 paul March 31, 2011 at 5:45 pm

@jeff

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?

Reply

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

Running sudo lsof -i gives me command not found?

Reply

9 sob March 28, 2012 at 12:33 pm

Thanks!

Reply

10 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”
Thanks.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 15 + 7 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.

Tagged as: , , , , , ,

Previous post:

Next post: