Testing TCP/UDP port connectivity from Linux
Check a remote port with telnet, nc, nmap or PortQry and list listening ports with lsof and netstat.
How to check from a Linux (or Windows) server that a remote TCP or UDP port is reachable, and which ports are listening locally. See also this guide.
Testing a remote port
With telnet (TCP)
telnet [hostname/IP address] [port number]
telnet 192.0.2.10 22
With nc / ncat (TCP)
nc -z -v [hostname/IP address] [port number]
nc -z -v 192.0.2.11 22
# Connection to 192.0.2.11 22 port [tcp/ssh] succeeded!
# nc: connect to 192.0.2.11 port 22 (tcp) failed: No route to host
With nc (UDP)
nc -z -v -u [hostname/IP address] [port number]
nc -z -v -u 192.0.2.12 123
NTP example (port 123): over TCP nc -z -v [hostname/IP address] 123, over UDP nc -z -v -u [hostname/IP address] 123.
With nmap
sudo nmap -p <PORT> 192.0.2.13
From Windows with PortQry
PortQry.exe -n example.com -e 80
Listing local listening ports
# With lsof
sudo lsof -nP -iTCP -sTCP:LISTEN
# With netstat
sudo netstat -tulnp | grep :22