Linux List The Open Ports And The Process That Owns Them

by Vivek Gite on May 30, 2008 · 8 comments

This is a user contributed quick tip.

How do you list the network open ports on your server and the process that owns them? The answer is simple use the following command (must run as root):
sudo lsof -i
sudo netstat -lptu

This article / faq / short tip is contributed by Vikrant Joshi. nixCraft welcomes readers' tips / howtos.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 8 comments… read them below or add one }

1 Jeff Schroeder May 30, 2008

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

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

Thanks

Reply

4 alojamento de sites July 22, 2010

Very useful, thanks

Reply

5 paul March 31, 2011

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

@paul: did you run the commands as root?

Reply

7 paul March 31, 2011

@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

Running sudo lsof -i gives me command not found?

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 11 + 4 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: