How to troubleshoot network applications with telnet

This article describes how to use the telnet program to troubleshoot network applications.

About telnet

For many years, the telnet program was the program of choice for connecting to a remote server. However, it sends data unencrypted, and SSH (Secure Shell) has almost completely replaced telnet as the preferred method for connecting to remote servers.

However, telnet is still valuable as a troubleshooting tool. You can use telnet to test TCP connections to a remote server on any port. Once telnet establishes a connection, you can send raw commands to do additional testing.

Enabling telnet

Linux includes the telnet client by default.

Windows 10 includes telnet as part of the Windows Subsystem for Linux. Telnet can also be installed on Windows 10 and older versions of Windows by following these instructions.

Macintosh OS X included telnet by default until recently. If your version does not include telnet, it can be installed following these instructions.

Don't want to install software? Try our articles on network troubleshooting using curl or using PowerShell and tnc. Just about every computer will have one of these three programs installed.

Using telnet to troubleshoot

To use telnet to troubleshoot a network application, you need to know at least two things:

  • The remote server name or IP address.
  • The port number for the network application you want to test.

If you are only testing basic connectivity to a particular network application, that is all you need to know. If you want to do more in-depth testing, however, you will need to know specific commands for the protocol you want to test (for example, HTTP or SMTP).

To open a connection to a remote server, open a terminal window on your computer, and then type telnet IP/host port, where IP/host represents the IP address or hostname of the server, and port represents the TCP port number. For example, to connect to example.com on port 80, type the following command:

telnet example.com 80
For a complete list of assigned TCP port numbers, please visit http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers.

When you try to establish a connection to a remote server, one of two things happens:

  • The server accepts the connection. If this happens, telnet may display some text from the server, or simply await further input.
  • The server rejects the connection. If this happens, you receive a message such as Connection refused or Connect failed.

The following sections demonstrate how to do basic telnet troubleshooting with some common network applications.

Troubleshooting web servers

Web server testing is probably the most common scenario for telnet troubleshooting. With telnet, you can open a connection to a remote server on port 80, and then send HTTP commands. For example, the following text shows an exchange between telnet and a remote web server. Text in red represents commands typed by the user:

$ telnet example.com 80
Trying 192.168.0.62…
Connected to example.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: example.com

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
[Additional server output follows]

In this exchange, telnet opens a connection to example.com on port 80. The user receives confirmation that there is a connection to the server, and then sends an HTTP command and request header. The HTTP response confirms that the server is accepting connections and responding to requests.

Troubleshooting mail (SMTP) servers

To test an SMTP server, use telnet to connect to port 25.

If you are testing connectivity to an A2 Hosting mail server, you can also use port 2525 or 587. Some ISPs block port 25 to help reduce spam on their networks.

The following text shows a sample exchange between telnet and a remote mail server. Text in red represents commands typed by the user:

$ telnet example.com 25
Trying 192.168.0.62…
Connected to example.com.
Escape character is '^]'.
220-example.com ESMTP Exim 4.7
220-We do not authorize the use of this system to transport unsolicited, 
220 and/or bulk e-mail.
EHLO a2example.com
250-example.com Hello a2example.com [192.168.3.232]
250-AUTH PLAIN LOGIN
QUIT

The SMTP responses show that the server is running and accepting requests.

Troubleshooting FTP

To test an FTP server, use telnet to connect to port 21.

The following text shows a sample exchange between telnet and a remote FTP server. Text in red represents commands typed by the user:

$ telnet example.com 21
Trying 192.168.0.62…
Connected to example.com.
Escape character is '^]'.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 18 of 50 allowed.
220-Local time is now 12:46. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.

The FTP server responds, indicating that it is active and running.

Troubleshooting SSH

SSH uses encrypted connections. However, you can still use telnet to verify that the service is running on a server.

The following text shows a sample exchange between telnet and a remote SSH server. Text in red represents commands typed by the user:

$ telnet example.com 22
Trying 192.168.0.62…
Connected to example.com.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3

The server returns a response indicating the current OpenSSH version.

Remember that A2 Hosting servers use port 7822 for SSH instead of the default port 22.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.