How to Install and Use Telnet on Ubuntu 20.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 Telnet server and client on an Ubuntu 20.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 running Ubuntu 20.04 server.
- 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 Mon 2021-04-29 10:24:05 UTC; 38s ago Docs: man:inetd(8) Main PID: 2883 (inetd) Tasks: 1 (limit: 1114) CGroup: /system.slice/inetd.service ??2883 /usr/sbin/inetd Apr 29 10:24:05 ubuntu2004 systemd[1]: Starting Internet superserver... Apr 29 10:24:05 ubuntu2004 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 20.04 LTS ubuntu2004 login: hitesh Password: Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-72-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Thu 29 Apr 2021 09:16:14 AM UTC System load: 0.83 Usage of /: 14.7% of 39.12GB Memory usage: 30% Swap usage: 0% Processes: 163 Users logged in: 0 IPv4 address for ens33: 192.168.0.100 IPv6 address for ens33: 2003:e1:bf4b:8b00:20c:29ff:fef5:ee3c * Pure upstream Kubernetes 1.21, smallest, simplest cluster ops! https://microk8s.io/ 8 updates can be installed immediately. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable Last login: Wed Apr 28 08:50:37 2021 from 192.168.0.20
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.