How to test network connectivity with telnet

This post is a follow on from my post last week regarding how to install the telnet client. The telnet client is simple yet extremely powerful in helping us gain a quick idea of where a problem may lie with TCP connectivity, it’s one of my first go to tools to use when testing a network connection to a server.

Performing a test with the telnet client

Now that the telnet client is installed (see my last post here if you have not done this yet) we can perform some basic network connectivity tests. The command is used in the format of ‘telnet hostname/ip address port‘ and entered into either command prompt or powershell under Windows, or through the shell in Linux or Unix. For example we can enter the below command to attempt connect to google.com on port 80:

telnet google.com 80

If this connection succeeds your command window will go blank, you can either terminate the session by pressing “control + ]” and then entering ‘quit’, or better yet from there you can issue commands to the server. In the above example we have connected to a web server on port 80 which is typically used to serve HTTP traffic, so we can issue HTTP commands as below:

GET /

After entering that into your blank telnet session you will not see any output until you press enter, at this point you should see a response from the web server. Although this is a basic test, if the session goes blank it confirms that we can establish a TCP connection on port 80 to the web server meaning there is likely a web server running on the remote host accepting our connections. Even better if we get a response to our GET command as this can confirm if the web server is responding and behaving as expected.

What if I get no response?

On the other hand if the telnet session does not succeed and fails to connect you may get output similar to the below.

C:\>telnet google.com 1111
Connecting To google.com...Could not open connection to the host, on port 1111: Connect failed

In this example I’m trying to connect to google.com on a random port 1111, however it fails, what could be the problem?

The remote server might not be listening on that port: The server you’re trying to connect to might not have any services listening on the port you’re trying to connect on, in this instance it will not respond and the connection will fail as it’s not expecting connections on the port. If you have access to the remote server you could run a command such as ‘netstat’ to get an idea of what ports the server is listening on and accepting connections for.

The remote server may not be responding on that port: The server you’re trying to connect to might be listening on the port, however it may be running a firewall which is configured to block the connection resulting in a failure of the telnet client. If you have access to the remote server confirm with ‘netstat’ that a service is listening on the port specified, then investigate any firewalls in use such as Windows firewall or iptables. The telnet client is a good tool for testing server security quickly if you want to see if a server is responding on a port that it shouldn’t be.

The connection may be blocked in your own network, or otherwise somewhere else along the route: Perhaps you are running a firewall in your own network which is blocking various outbound ports, the connection attempt may not even leave your local network depending on your configuration. You could simply try disabling your firewall and performing the test again to rule this out as being part of the problem.


Summary

As you can see there are plenty of reasons a telnet connection may or may not succeed, however being able to test this by enabling the telnet tool has allowed us to perform additional troubleshooting steps to get an idea of where potential connectivity problems may lie.

  1. How to enable the telnet client in Windows 8.1 | Root Users - pingback on February 18, 2015 at 7:17 am
  2. How to "ping" a port | Root Users - pingback on March 11, 2015 at 12:08 am
  3. How to enable the telnet client in Windows 10 | RootUsers - pingback on April 27, 2015 at 11:30 pm
  4. How To Enable Telnet Client in Windows Server 2016 | RootUsers - pingback on August 22, 2015 at 12:01 am
  5. Hi, say for instance telnet connection is fine however GET / not giving any response, then what can be the issue, thanks in advance :)

    • If it connects alright that would indicate that the connectivity is alright and any firewalls are allowing the connection through, however the application is not correctly responding. Due to this if possible I’d look at the logs of the application, or the configuration to find out why it’s not responding as expected.

  6. how to calculate the time taken to perform the telnet to a hostname: port to determine if there is any latency?

    Found:

    https://serverfault.com/questions/649532/what-is-the-best-way-to-measure-latency-via-a-telnet-to-port-test-preferably

    Found this but not sure if using time is reliable.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackbacks and Pingbacks: