Last Updated: February 25, 2016
·
1.135K
· akhilravidas

Basic TCP Handshake

When debugging issues on remote servers which appear overloaded, it is helpful to check if they are listening and accepting connections on a given port as a first heuristic.

Commands like telnet and netstat can be useful in these cases. To do a basic tcp handshake using netstat:

nc -zvw 1 <host> <port>

For ex:

nc -zvw 1 localhost 22 

The above command would return succeeded or failed depending on whether you have an ssh daemon running

Flags: -v flag specifies verbose output (to stderr), -w specifies the timeout in seconds (in this case 1), so that this can also be used in non-interactive scripts. -z makes sure that no data should be sent. You can find more details at: man nc