Linux – How to show listening open ports from the shell

linuxunixwindows

I always have to google this and ServerFault is never the first result. Typically I want to do this on a unix box, but I'd also like to know how to do it on a Windows machine from CMD.exe.

Best Answer

Use netstat -pl on Unix. Option -p shows process PID/name and option -l shows only listen sockets.

On Windows, use netstat -oa. Option -o is the same as -p on Unix. Option -a is also the same on Unix, it shows all sockets. You'll have to look only at LISTENING lines since Windows' netstat doesn't provide an option to show only listen sockets.

If you don't want to resolve IP addresses to name (which can take a great amount of time), use option -n