Checking network connectivity outside an application helps to determine if the connection problem is application-related or network-configuration related. To check connectivity to a remote host you could use several tools on the host.
NC
The nc command also known as netcat is an extremely versatile network tool. It can be used among other things to test connectivity to a specific port. It can also work as a more powerful version of the old telnet. The difference is that with the below configuration it will try to open the specified port and if successful it will close the connection immediately and report. It also allows specifying a timeout.
The syntax for testing connectivity to a port:
nc -zv -w timeout host port
Example:
$ nc -zv -w 10 google.com 80
Connection to google.com port 80 [tcp/http] succeeded!
If you are using a Proxy:
nc -x <proxy>:<port> -X connect -zv -w 10 host port
Example:
~: $ nc -x 127.0.0.1:8080 -X connect -zv -w 10 anypoint.mulesoft.com 443
nc: Proxy error: "HTTP/1.1 200 Connection established"
Telnet
In case the nc command is not available you could use the telnet command. If you see an output similar to the one below it means there is connectivity.
Syntax:
telnet host port
Example:
$ telnet google.com 80
Trying 173.194.42.65...
Connected to google.com.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
After connecting, if the remote server doesn't close the connection you may need to abort the command by pressing CONTROL and the right bracket key (']') and then write quit ENTER.
Example:
If the connection is not successful you could see an error similar to this:
$ telnet localhost 8734
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
Needless to say, the nc command is more convenient for testing connectivity.
Ping
One of the most common tools for testing connectivity is the ping command. Unfortunately it has some limitations mentioned below that limit its usefulness.
Syntax:
ping host
Example:
$ ping google.com
PING google.com (173.194.42.69): 56 data bytes
64 bytes from 173.194.42.69: icmp_seq=0 ttl=56 time=1.551 ms
64 bytes from 173.194.42.69: icmp_seq=1 ttl=56 time=1.641 ms
^C
Note that in some platforms you'll need to stop ping manually if you don't use a limiting parameter.
Ping has some limitations:
-
This command also tests that there is connectivity with a server but not with a particular port.
-
Ping uses the ICMP protocol that is disabled in some systems for security reasons.
This means that ping may not be adequate or available to test connectivity to a specific service.
My traceroute (mtr)
mtr is analogous to the top command in that it refreshes on its own and gives you a live look at network response and connectivity, This would help to identify packet loss along the path between source and destination.
Please refer to the article How to use mtr to diagnose packet loss problem with a TCP port for details.
USEFUL LINKS:
How to Test Network Connectivity Using PowerShell on Windows