Testing remote port connectivity - Linux hack

Testing remote port connectivity - BASH

On occasion, Telnet is not installed on a system, making it difficult to test if a remote port is connectable or not. If this is the case, the below method using simple Linux devices can help diagnose a remote port connectivity issue.

Using bash to test a remote port

Linux has a built in handler to test port connectivity in theĀ /dev/tcp/ directory. Using the below is a handy way to test remote port connectivity.

Connection successful

#> timeout 1 bash -c 'cat < /dev/null > /dev/tcp/google.com/80'
#> echo $?

Connection failure prior to the timeout

#> timeout 1 bash -c 'cat < /dev/null > /dev/tcp/sfsfdfdff.com/80'
bash: sfsfdfdff.com: Name or service not known
bash: /dev/tcp/sfsfdfdff.com/80: Invalid argument
$ echo $?

Connection not established before the timeout value of 1 second

#> timeout 1 bash -c 'cat < /dev/null > /dev/tcp/google.com/81'
#> echo $?