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):
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 10 comments… read them below or add one }
Shameless plug to a really good article I wrote about lsof and some of the more nifty tricks:
Troubleshooting running systems with lsof
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.
Thanks
Very useful, thanks
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.
@paul: did you run the commands as root?
@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?
Running sudo lsof -i gives me command not found?
Thanks!
What music is played in the video “Linux List The Open Ports And The Process That Owns Them”
Thanks.