How can I list my open ports on Debian?
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.
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.
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).
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.
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.
You can do:
netstat -an | egrep 'Proto|LISTEN'
or simply:
netstat -anl
which will give you all listening sockets on the system.