Linux List The Open Ports And The Process That Owns Them

Posted on in Categories Howto, Linux, Monitoring, RedHat/Fedora Linux, Security, Sys admin, Tips, Troubleshooting last updated May 30, 2008

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 12 comments/add one below):

12 comment

    1. Hi,

      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
      Ankita

  1. 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.

  2. 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.

  3. @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?

    1. 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.

Comments are closed.