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

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
12 comments… add one
  • Jim Aman Feb 28, 2013 @ 19:59

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

  • sob Mar 28, 2012 @ 12:33


  • Mark Nett Jan 5, 2012 @ 11:51

    Running sudo lsof -i gives me command not found?

    • Sarjeet Singh Aug 13, 2013 @ 23:38

      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.

  • paul Mar 31, 2011 @ 17:45


    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?

  • Jeff Schroeder Mar 31, 2011 @ 6:35

    @paul: did you run the commands as root?

  • paul Mar 31, 2011 @ 3:08

    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.

  • alojamento de sites Jul 22, 2010 @ 12:29

    Very useful, thanks

  • harsha gowda Jul 10, 2008 @ 11:36


  • Mark Nixon May 30, 2008 @ 18:42

    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.

  • Jeff Schroeder May 30, 2008 @ 12:50

    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 Apr 21, 2015 @ 6:24


      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

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @