Using Telnet to Test TCP Services

The following introduction is based on telnet, a program that is found in virtually all computer systems. It does not require root privileges and can be run on a virtual machine over a terminal.

Originally, telnet [host address] was used to remotely administrate servers over a network, but it was extremely insecure and has been replaced with ssh.

Nonetheless, telnet is useful for quickly setting up TCP connections and testing out certain services. To connect to port 80 to test a web server, use the following:

$ telnet 80

Output similar to the following will appear:

Connected to
Escape character is '^]'.

You have a couple of seconds to type responses back to the server. If you wait too long, the connection will be automatically closed.

Request a web page with by typing the following:

GET / HTTP/1.1
[press the return key]
[press the return key again]

You will get a page full of HTML, and depending on the server, the connection will either close or stay open for another request.

Additionally, you can test SMTP servers using:

$ telnet 25

Then, enter the following commands:

helo example
mail from: Person rcpt to: Example
Subject: Greetings!
Hello there.[press the return key]
[press the return key again]
.[press the return key]

You can read more about the SMTP and the HTTP protocols elsewhere.

These examples show that telnet is useful for testing simple connections when a full-blown web browser or email client is too troublesome to install and configure.