In this tutorial, we intend to teach you to Install and Use Telnet on Ubuntu 20.04.
Telnet is a network protocol used to virtually access a computer and to provide a two-way, collaborative, and text-based communication channel between two machines.
It follows a user command Transmission Control Protocol/Internet Protocol (TCP/IP) networking protocol for creating remote sessions. On the web, Hypertext Transfer Protocol (HTTP) and File Transfer Protocol (FTP) simply enable users to request specific files from remote computers, while, through Telnet, users can log on as regular users with the privileges they are granted to the specific applications and data on that computer.
How To Install and Use Telnet on Ubuntu 20.04
To install Telnet, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide the Initial Server Setup on Ubuntu 20.04.
Now follow the steps below to complete this guide.
Install Telnet on Ubuntu 20.04
By default, the Telnet server package is available in the Ubuntu 20.04 default repository.
First, update your local package index with the command below:
sudo apt update
Then, use the command below to install Telnet on your server:
sudo apt install telnetd -y
When your installation is completed, verify that is active and running on your Ubuntu 20.04:
sudo systemctl status inetd
Output ● inetd.service - Internet superserver Loaded: loaded (/lib/systemd/system/inetd.service; enabled; vendor preset:> Active: active (running) since Wed 2022-08-17 10:45:08 CEST; 46s ago Docs: man:inetd(8) Main PID: 1609 (inetd) Tasks: 1 (limit: 2282) Memory: 792.0K CGroup: /system.slice/inetd.service └─1609 /usr/sbin/inetd
How To Connect to Telnet Server
At this point, to connect to your remote system running Telnet, you will need to set up an allow rule. By default, Telnet runs on port 23.
Setting up an allow rule in UFW can be done in several ways. It is highly recommended to give the IP of the connecting server only if at very worse the subnet. Do not leave port 23 open to everything, and this will lead to brute force attempts.
The rule for single IP:
sudo ufw allow from 188.8.131.52 to any port 23
Allow from subnet:
sudo ufw allow from 184.108.40.206/24 to any port 23
Now that you have set up a UFW rule so you can connect to your remote server using Telnet, use the following (telnet) command:
Output Trying 192.168.50.15... Connected to 192.168.50.15. Escape character is '^]'. Ubuntu 20.04 LTS ubuntu2004 login: olivia Password: Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.15.0-41-generic x86_64) ...
How To Test Open Ports with Telnet
Also, you can easily use Telnet to test open ports on a remote system.
For example, to test port 80 on the remote system (IP 192.168.50.15) run the following command:
telnet 192.168.50.15 80
If port 80 is open, you should see the following output:
Output Trying 192.168.50.15... Connected to 192.168.50.15. Escape character is '^]'.
If port 80 is blocked or the Telnet service is not running. You should see the following output:
Output Trying 192.168.50.15... telnet: Unable to connect to remote host: Connection refused
Test a Mail Server with Telnet
The Telnet command is also very useful to test a mail server. Connect to a mail server using Telnet:
telnet 192.168.50.15 25
If the connection is successful, you will see a response from the other server similar to this:
Output Trying 192.168.50.15... Connected to 192.168.50.15. 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:
The mail server will show you then which methods it supports.
To quit the connection, enter the command quit.
Output 221 2.0.0 Bye Connection closed by foreign host.
Note: 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.
At this point, you learn to Install and Use Telnet on Ubuntu 20.04.
Hope you enjoy it.
Also, you may be interested in these articles:
How to Install and Use Docker on Ubuntu 20.04
Install and Secure Plausible Analytics on Ubuntu 20.04
How To Install Node.js on Ubuntu 20.04