Knowledge Base

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 and Mac OS X include the telnet client by default. Microsoft Windows XP and earlier versions of Windows also have telnet enabled by default. On Windows Vista and later versions, however, you must enable telnet in the Control Panel before you can use it. To do this, follow these steps:

  1. Click the Start menu, and then click Control Panel.
  2. Click Programs and Features.
  3. Click Turn Windows features on or off.
  4. In the list of Windows featuers, scroll down and then select the Telnet Client check box.
  5. Click OK. It may take a few minutes for Windows to enable the program.
  6. To confirm that the telnet client is active, click the Start menu, and then click Run.
  7. In the Open text box, type cmd and then click OK. A command prompt window appears.
  8. At the command prompt, type telnet and then press Enter. If the telnet client is enabled, you see Welcome to Microsoft Telnet Client.
  9. At the Microsoft Telnet prompt, type set localecho. This option ensures that any text you type on the local computer appears on the screen. Otherwise, you will be unable to see what you type.
  10. Type quit to return to the DOS command prompt.

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. 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.