Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the command to display a list of open ports on a Debian server?

I tried netstat -a | egrep 'Proto|LISTEN' but I would like something more specific that actually lists the port number.

share|improve this question
 netstat -pln

-l will list listening ports, -p will also display the process, -n will show port numbers instead of names. Add -t to only show TCP ports.

share|improve this answer
For the -p to work properly, you need to run this as root, so sudo netstat -tpln, otherwise the process column will not be particularly useful, unless you're the user whose process is listening on a given port. – cjc Feb 6 '12 at 18:21

lsof -i -P

Check the man page for lsof as there is no shortage of options. -P lists the port number rather than the name taken from /etc/services Run as root, though, this will provide you with a list of all active network connections and their status (listening, established, etc).

share|improve this answer

You can do:

netstat -an | egrep 'Proto|LISTEN'

or simply:

netstat -anl

which will give you all listening sockets on the system.

share|improve this answer
This would be the best solution (where "best" is defined as "works on the broadest range of systems" (BSD, Linux, AIX, Solaris, I believe HP-UX)) – voretaq7 Feb 6 '12 at 22:31

What almost everybody wants (TCP and UDP) is netstat -tunlp.

I use it every day, maybe every hour. The 'lsof' hack is more portable (works on Solaris too), but on Debian it's not an essential package, you have to install it.

share|improve this answer
Yes, and run it via sudo. – Martijn Heemels Feb 7 '12 at 23:09
My friend taught me to remember this command with a flower name netstat -tulpen Flag e gives additional information. – Deele Dec 15 '12 at 14:37

TechRepulic has a decent article that you can find here. It has some similar commands as you listed above but also a few variations. I would also highly recommend using nmap to do a port scan of the computer in question so you can see from an external perspective what ports are open and listening.

share|improve this answer
Could you please tell me why this was down voted? As I simply provided a link with a lot of the solutions above which were approved along with a different perspective of doing an external scan as well. Thanks. – Eric Feb 6 '12 at 19:10
I didn't downvote, but on serverfault like most stack-exchange we generally expect you to to put the answer here, and not just a link to somewhere else. Links go away over time, but we want content on SF to still be valuable when the links die. – Zoredache Feb 6 '12 at 22:55
The only line of code that the above article link has is sudo nmap -T4 -A -v everything else is go do this - go do that without any details... Its like reading the back cover of a book - lots of words without meat. – KingsInnerSoul Apr 1 at 14:37

I'm a big fan on netstat -ntlp and lsof -i, both mentioned already.

A new(er) command to me is ss.

The invocation is like:

ss -l

It's good to have options, in terms of commands and flags.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.