How to Install and Use Telnet on Ubuntu 22.04 LTS

Telnet is a terminal emulation program for TCP/IP networks that allows you to access another computer on the Internet or on a local network by logging on to the remote system. Telnet is a client-server protocol that connects to port 23 of the Transmission Control Protocol. You can also use Telnet to check open ports on a remote system.

In this tutorial, you will learn how to install and use the Telnet server and client on an Ubuntu 22.04 LTS server.

WARNING: Telnet is an unencrypted and therefore insecure protocol. This guide is for educational purposes only and is not a recommendation to use Telnet Server on your system. This guide will show you how to install and use the Telnet client and server in case you want to learn more about this ancient server administration protocol or in case you want to use the Telnet client to test your mail server. We do NOT recommend using Telnet (Server) on today's servers, especially if you use it over the Internet. To manage your server over the network, use SSH instead of Telnet. Using a Telnet client is something different. A Telnet client is a useful tool for testing your mail or web server, for example, as shown below.

Requirements

  • A server with Ubuntu 22.04 installed.
  • A non-root user with sudo privileges.
  • A static IP address 192.168.0.100 configure on your server.

Install Telnet Server

By default, the Telnet server package is available in the Ubuntu 20.04 default repository. You can install it by just running the following command:

sudo apt install telnetd -y

Once the installation is completed, you can check the status of Telnet service using the following command:

sudo systemctl status inetd

Output:

? inetd.service - Internet superserver
   Loaded: loaded (/lib/systemd/system/inetd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2022-08-04 09:10:22 UTC; 24s ago
     Docs: man:inetd(8)
 Main PID: 1158 (inetd)
    Tasks: 1 (limit: 1114)
   CGroup: /system.slice/inetd.service
           ??1158 /usr/sbin/inetd

Aug 04 09:10:22 ubuntu2204 systemd[1]: Starting Internet superserver...
Aug 04 09:10:22 ubuntu2204 systemd[1]: Started Internet superserver.

Test Telnet Connection from Remote System

Telnet server is now installed and listening on port 23. It's time to connect the Telnet server from the remote system.

Now, log in to another Ubuntu system and run the following command:

telnet 192.168.0.100

You will be asked to enter your username and password. After successful authentication, you should see the following output:

Trying 192.168.0.100...
Connected to 192.168.0.100.
Escape character is '^]'.
Ubuntu 22.04 LTS
ubuntu2204 login: hitesh
Password:  
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-41-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
Last login: Mon Jul 25 09:51:42 2022 from 192.168.0.22

You can now run any command on the Telnet server using Telnet.

Use telnet to Test Open Ports

You can also use Telnet to test open ports on a remote system.

For example, to test port 80 on the remote system (IP 192.168.0.100) run the following command:

telnet 192.168.0.100 80

If port 80 is open, you should see the following output:

Trying 192.168.0.100...
Connected to 192.168.0.100.
Escape character is '^]'.

If port 80 is blocked or the Telnet service is not running. You should see the following output:

Trying 192.168.0.100...
telnet: Unable to connect to remote host: Connection refused

Use Telnet command to test a Mail Server

The Telnet command is also very useful to test a mail server. Connect to a mail server using Telnet

telnet 192.168.0.100 25

If the connection is successful, you will see a response from the other server similar to this:

Trying 192.168.0.100...
Connected to 192.168.0.100.
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (Debian/GNU)

Now you can respond to the server with the ehlo command, followed by your sender domain name. Example:

ehlo mydomain.tld

The mail server will show you then which methods it supports.

250-server1.example.com
250-PIPELINING
250-SIZE
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING

To quit the connection, enter the command quit.

quit

The result will be:

221 2.0.0 Bye
Connection closed by foreign host.

The full command sequence is:

[email protected]:~# telnet 192.168.0.100 25
Trying 192.168.0.100...
Connected to 192.168.0.100.
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (Debian/GNU)
ehlo mydomain.tld
250-server1.example.com
250-PIPELINING
250-SIZE
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
quit
221 2.0.0 Bye
Connection closed by foreign host.
[email protected]:~#

This test procedure is useful if you like to find out if mail services (port 25) are blocked by your internet service provider or data center.

Share this page:

Suggested articles

6 Comment(s)

Add comment

Comments

By: jogi at: 2020-04-08 13:43:46

i have ubintu 18.4 and i want to control my windows pc from ubunto , what port numbe i should use o

By: Peter Roy at: 2020-07-08 15:05:58

The port you use is up to you. Choose wisely and > 1024. Every server by defenition has a port, http will be 80 and https will be 443. If you use vnc or rdp the port will be by defenition diferent. Either use the default fort each service or choose wisely.

By: Sifa at: 2020-05-19 06:10:21

So far the most comprehensive tutorial i have seen about telnet on the internets. Thank you

By: Richard at: 2021-03-31 18:02:41

It might be helpful to mention how to end a connection when testing open ports. I tried - exit, logout, end - and a few others. I guess it's supposed to be - close.

By: mostafa at: 2021-11-01 17:21:54

I try it with this command:

telnet localhost:2121

and I got that error, next I tried it with this command and its work for me

telnet localhost 2121

By: Time Rider at: 2021-12-29 22:20:36

I have successfully installed "telnet" in my Ubuntu, but it gets stuck at:

Connected to irc.example.com.

Escape character is '^]'.

And nothing happens. What should I do?