To check if a port is reachable on Linux
This is tested using nc version 7.50 (package nmap-ncat) on Amazon Linux.
nc -vz localhost 22
Connection to localhost 22 port [tcp/ssh] succeeded!
On a higher version if you get ncat: invalid option — ‘z’ error, then use the following command
cat /dev/null | nc -v localhost 22