Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

5 Answers 5

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
4  
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

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

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

Your Answer

 
discard

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.