How To Check Connectivity Between Two Servers
In an era of interconnected devices, the code we write involves connectivity from one machine to another remote machine. In other words, while working on a frontend application, it needs to communicate with another remote API. It's essential to understand if the connectivity exists between the two machines and if the port for the destination machine is open and accessible.In this article, I will explore a few techniques to test the network connectivity with another machine & port number using the built-in tools in the Operating System. No additional downloads or installation is required. Once we establish the connectivity between two machines, we can proceed ahead with our implementation details. However, if network connectivity is not established, we may need to further troubleshoot the issue.
- How To Check Port Connectivity Between Two Servers Windows
- How To Check Connectivity Between Two Servers Pc
You might find these helpful in case you need to verify the connectivity to remote machines.What are the various steps to verify connectivity to the destination machine & port?. The first step in this process is to verify the network connectivity with the remote machine. It means checking if we can send packets to the remote machine or not.
Next, verify the connectivity to the destination port to check if the port is blocked or inaccessible. This ensures that the firewall is not blocking the port. Check Connectivity between machines using PingUsing the Ping command, we can verify the network level connectivity between the client and Remote Machine. At the N/w level Ping rely on ICMP, which is at layer 3. Hence, it doesn't check if a port is open or not. So, it is possible that ping works, but still, the call to the API on destination machine at the specific port doesn't work.How to use ping?. Open the command prompt.
How To Check Port Connectivity Between Two Servers Windows
Enter ping command, passing the destination machine IP or Hostname as shown below.Successful ResponseIf Ping Succeeds, we will get a reply from the destination machine. This reply ensures that the connectivity exists between the source and destination machines. The following image displays the result of a successful ping response. Check Connectivity between machines Using TelnetWikipedia defines Telnet as 'a protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection.' At N/w level, Telnet works in the application layer and needs the port connectivity.Telnet gets its name from Terminal Network. With Telnet, we can establish a host session to a server. The advantage of using Telnet is that we can verify the connectivity to a port as well.Why is Telnet not preferred?Telnet uses plain text for communication and hence is not encrypted.
Therefore, in Windows, by default the TelNet Client is disabled.Telnet can be enabled in Windows by Adding/Removing windows component using Control Panel.How to use Telnet?. Enter command prompt. Use telnet command in the Destination Server Name/Address and the port number; e.g., telnet destination, as 80.NoteThe default port for Telnet is 23. So, if we omit the port number in the Telnet command, the Telnet will try to connect to the destination using port 23.Telnet succeedsAfter entering the Telnet command, we will see the text connecting to HostName, as shown in the below image. If the destination Machine or the port is inaccessible, we will get the error 'Could not open connection to the host, on port 80: Connection failed'What if Ping works successfully and Telnet fails?It might be the case that the port is blocked. The firewall can block the traffic. This firewall can either be on your local machine or the server.
How To Check Connectivity Between Two Servers Pc
Check both ends for a firewall. If the actual server is on a different network, for example across the Internet, there could be other firewalls in the middle too.Check Connectivity between machines using PowershellMy preferred option is Powershell. It is powerful as it allows us to explore all the potential of a.net framework as we can call.NET Framework methods using Powershell.Option 1 - Test-NetConnectioncommandIf you're running Windows 8/Windows Server 2012 or newer, you can use the Test-NetConnectioncommand.The Test-NetConnection cmdlet displays diagnostic information for a connection. It supports ping tests, TCP tests, route tracing, and route selection diagnostics.
For our purposes, we are going to use the cmdlet with destination name and the port number. Option 2 - System.Net.Sockets.TcpClientAnother option using PowerShell is making use of the.Net Class TcpClient. This class has a constructor which takes in the Destination Server Name and the Port number.This constructor creates a new TcpClient and makes a synchronous connection attempt to the provided host name and port number. TcpClient will block until it either connects or fails. This constructor allows you to initialize, resolve the DNS hostname, and connect in one convenient step.How to use Powershell TcpClientCreate a new object using the TcpClient class as shown below, passing in the HostName/IP and the Port Number.SuccessIf the Connected Property is True, then connectivity succeeds.