91

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.

stew
  • 9,588
leonel
  • 1,049
  • 2
  • 8
  • 8

9 Answers9

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

Stone
  • 7,279
38

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

Jeff Ferland
  • 20,987
18

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.

dmourati
  • 26,498
13

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.

zerodeux
  • 666
7

You can do:

netstat -an | egrep 'Proto|LISTEN'

or simply:

netstat -anl

which will give you all listening sockets on the system.

Karlson
  • 241
2

Listening ports are not the same as ports open from the outside. You need to consider the firewall. If you try a program like nmap from another computer then you will be able to see the open ports not blocked by firewall.

0

merged all answers to:

  • Debian check listening port
    • methods
    • common parameters
      • -p: show related process
      • -t: tcp port
      • -l: only show listening port
      • -n == --numeric: Do not try to resolve service names
      • -i: select IPv[46] files
      • -P: no port names
crifan
  • 121
0

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.

Eric
  • 1,403
  • 3
  • 19
  • 34
0

I prefer to use instead:

netstat -antp 
lsof -i 
netstat -lptu
netstat -tulpn
XsiSec
  • 101