What is the command to display a list of open ports on a Debian server?
netstat -a | egrep 'Proto|LISTEN' but I would like something more specific that actually lists the port number.
-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).
What almost everybody wants (TCP and UDP) is
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.
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:
It's good to have options, in terms of commands and flags.
You can do:
netstat -an | egrep 'Proto|LISTEN'
which will give you all listening sockets on the system.
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.
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.
I prefer to use instead:
netstat -antp lsof -i netstat -lptu netstat -tulpn