Telnet is a popular network protocol that lets you connect to a remote computer virtually. It is an old protocol developed in 1969.

Nowadays, SSH(Secure Shell) has replaced Telnet. SSH is also a network communication protocol that lets network and system administrators connect to remote computers securely.

As for Telnet, it is now predominantly used to troubleshoot and test connection issues. Learning Telnet commands can help you manage your networks better.

In this article, we’ll take a closer look at telnet command, including learning how it works and how to troubleshoot connection issues. Let’s get started.

What is Telnet?

Telnet is a network protocol that stands for Teletype Network. It offers a command-line interface/interpreter to communicate with the remote server. System and network administrators use Telnet’s terminal-to-terminal communication to gain remote control and perform different actions, such as initial device setup.

To facilitate Telnet protocol, you need Telnet Client. The client enables users to sign in and use applications on remote systems through TCP/IP. The Telnet client uses a Telnet server application to carry out the operations. Moreover, Telnet Client is available on all modern operating systems, such as Windows, Linux, and macOS.

Note: In the article, when we mention “Telnet,” it means “Telnet Client,” if otherwise mentioned.

Is Telnet Secure?

During its inception in 1969, security was not the main concern when performing network tasks. That’s why Telnet didn’t use any encryption. As it is not secure, it is also not recommended for connecting to remote clients over TCP/IP network.

If you do, you expose yourself to hackers that can interrupt unencrypted data. SSH is a great alternative protocol that offers a secure way to connect to a server remotely.

How does Telnet work?

Visually, the Telnet protocol works as below.

Internet
How Telnet Works

Telnet is a text-oriented communication that creates a bidirectional(client-server protocol) interactive communication system. It utilizes an eight-byte connection to do the transmission. Also, you need a keyboard and screen connected to the terminal to use Telnet.

You enter a command from your terminal to connect to a remote computer. Once connected, Telnet provides you control over the server, including its files and process.

To connect to a remote server, the user should enter “Telnet” in the command prompt. The syntax is:

telnet hostname port

Once successfully connected, you can use the Telnet prompt to enter more Telnet commands.

The different things that you can use Telnet for are:

  • Check open ports
  • Edit files, run programs
  • Configure network devices such as switches, routers, etc.

To end the session, you need to type “Telnet” into the Telnet prompt.

How to enable Telnet Client in Windows/Linux and macOS

Telnet client is available on all the major platforms and operating systems. However, you need to install or enable it before you can use it.

#1. Windows

If you’re using Windows 7 or above (8, 10, 11) or Windows Vista, you can enable the Telnet client by following the steps below:

  • Go to the start menu and search for Control Panel. You can also open Control Panel by pressing Win + R and then typing “control.” It should open up the Control Panel.
  • Now select “Programs” > “Programs and Features.”
  • Select “Turn Windows features on or off from the left pane.”
  • Now check the box next to “Telnet Client” and press “OK.”
  • Now, press “Close” once Windows enables it and shows the message, “Windows completed the requested change.”
telnet-client-enable-windows
Enabling Telnet in Windows

Note: You can start using Telnet Client immediately without restarting your computer.

#2. Linux

Just like Windows, Linux also doesn’t come pre-installed with Telnet.

To install Telnet in Ubuntu, you need to use the following command.

# sudo apt-get install telnet

Note: The command differs depending on your Linux distro.

#3. macOS

MacOS also supports Telnet. To install it, you need to use Homebrew. If Homebrew is not pre-installed, you can install it by running the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It’ll ask you to enter the administrator password to authorize the installation.

With Homebrew installed, type the following command to install Telnet on MacOS.

brew install telnet

Using Telnet to test and troubleshoot network connections

Even though Telnet is not ideal for remote connectivity, it is still useful for testing and troubleshooting network connections.

Before we proceed, let’s take a quick look at Telnet syntax.

telnet <server/host IP address> <port>

Here, the server/host IP address is the server you want to connect to. The port is the TCP port number.

For example, if you want to connect to server IP address example.com with port 80, you need to type the following command.

telnet example.com 80

This means you must know the remote server IP address/name and port number to troubleshoot beforehand. 

Let’s get started.

Troubleshooting web servers

Telnet offers an easy way to test server connectivity. All you need to do is connect to the server/host IP address and the port which accepts a connection.

For example, if you’re connecting to 23.45.75.22 at port 532, you need to run the following command.

telnet 23.45.75.22 532

From here, two things can happen:

  1. The connection to the server is successful. It’ll show “connected to the server” or any other confirmation message or wait for additional input.
  2. The connection to the server is unsuccessful. In that case, you can get messages such as “Connection failed” or “Connection refused”
  3. Telnet is not returning any messages. 

Multiple reasons for failed Telnet attempts to connect to a remote server exist. Also, if Telnet is not returning any error message, it can be a firewall or antivirus blocking the connection at your end or the server.

If we connect to geekflare.com at port 80, you’ll see an instant connection as it waits for further commands.

telnet geefklare.com 80
Connected to geekflare.com.
Escape character is '^]'.

Now, enter the following command.

GET / HTTP/1.1
Host: geekflare.com

It’ll return the following:

HTTP/1.1 200 OK
Date: Fri, 18 Nov 2022 04:40:33 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 16
X-Frame-Options: SAMEORIGIN
Referrer-Policy: same-origin
Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
[Additional server output follows]

Now, look at the failed attempt to connect to a server.

telnet 23.45.75.222 532
Connecting To 23.45.75.222...Could not open a connection to the host on port 532: Connect failed

Check if a port is open

If a server is accessible remotely with Telnet, you can also use it to check whether a port is open. 

To check if a port on your server is open, you need to use the following command.

telnet <server IP address> <port>

For example, your server IP address is 23.45.47.53, and the port you want to check is 532.

telnet 23.45.47.53 532

If the command is a success, you will get a blank screen which means the port is open. If it reads as “connecting..” and then shows an error message, it means the port is not open.

Connection to 23.45.47.53:532 - fail
Error #110 (Connection timed out)

Troubleshooting SMTP mail servers

Simple Mail Transfer Protocol(SMTP) manages the communication between mail servers. 

You can troubleshoot SMTP servers with Telnet to see if they’re receiving and sending messages. You send manual message requests to the SMTP server. If everything is fine, you’ll get a response.

Telnet lets you test STMP connection in two ways:

  1. Test the mail flow from the internet to your mail server.
  2. Test the mail flow from your mail server to another server.

To run a sample exchange, type the following command in your terminal.

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

QUIT

Here, the two other commands typed by the user are:

  1. EHLO mail.geekflare.com
  2. QUIT

The ECLO command identifies the domain name before using the MAIL FROM command. The QUIT command exit the Telnet session.

If you want more advanced commands, check out this article on Using Telnet to test SMTP communication on Exchange servers.

Troubleshooting FTP server

Just like SMTP and web servers, you can also troubleshoot FTP servers. All you need to do is enter the FTP server IP address and connect to port 21.

telnet ftp.geekflare.com 21

You are now connected to the server if the attempt is successful. Otherwise, you’ll see an error message.

Error #0 (php_network_getaddresses: getaddrinfo failed: No address associated with hostname)

Troubleshooting SSH

SSH is the modern take on secure connections and replaces Telnet. You can use Telnet to see if the server is running SSH.

To do so, use the Telnet command with the server IP address and port 22.

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

Final Words

Telnet is a handy tool in current times. It lets you successfully troubleshoot network connections without relying heavily on more complex tools or command lines. Using Telnet, you can check if you can access a web server, see if a port is open, and troubleshoot SSH and FTP.

You may check out this article on how to resolve ‘telnet command not found’ error.