Telnet is a powerful terminal emulation program that enables users to access remote systems on TCP/IP networks. With Telnet, you can connect to another computer on the Internet or a local network by logging into the remote system. While Telnet is an ancient server administration protocol, it can still be used for educational purposes or to test your mail server. However, it’s essential to note that Telnet is an unencrypted and insecure protocol, so it’s not recommended for use on modern servers, especially over the Internet. Instead, consider using SSH for secure network management. Nevertheless, a Telnet client can be a helpful tool for testing your mail or web server. In this tutorial, we will guide you through the process of installing and using Telnet on an Ubuntu 22.04 LTS server.

Requirements

Before proceeding with the installation and configuration of Telnet on your Ubuntu 22.04 LTS server, ensure that you have the following prerequisites:

  • A server running Ubuntu 22.04 LTS.
  • A non-root user with sudo privileges.
  • A static IP address (e.g., 192.168.0.100) configured on your server.

Installing Telnet Server

The Telnet server package is readily available in the default repository of Ubuntu 22.04 LTS. To install it, open a terminal and run the following command:

sudo apt install telnetd -y

After the installation is complete, you can verify the status of the Telnet service by running the following command:

sudo systemctl status inetd

If the Telnet server is successfully installed, you should see an output similar to the following:

? 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

Testing Telnet Connection from a Remote System

Now that the Telnet server is installed and listening on port 23, you can test the Telnet connection from a remote system. Log in to another Ubuntu system and open a terminal. Run the following command to connect to the Telnet server:

telnet 192.168.0.100

Replace “192.168.0.100” with the IP address of your Telnet server. Once you execute the command, you’ll be prompted to enter your username and password. After successful authentication, you should see an output similar to the following:

Trying 192.168.0.100...
Connected to 192.168.0.100.
Escape character is '^]'.
Ubuntu 22.04 LTS
Ubuntu2204 login: shapehost
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

Congratulations! You have successfully connected to the Telnet server.

Using Telnet to Test Open Ports

In addition to accessing remote systems, Telnet can also be utilized to test open ports on a remote system. To test port 80 on a specific IP address (e.g., 192.168.0.100), execute the following command:

telnet 192.168.0.10080

If port 80 is open, you will see an output similar to the following:

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

On the other hand, if port 80 is blocked or the Telnet service is not running, you will encounter the following output:

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

Using Telnet to test open ports can be a valuable method to determine if mail services (port 25) are blocked by your internet service provider or data center.

Testing a Mail Server with Telnet

The Telnet command is particularly useful for testing a mail server. To connect to a mail server using Telnet, execute the following command:

telnet 192.168.0.10025

Replace “192.168.0.100” with the IP address of your mail server. If the connection is successful, you will receive a response from the mail server similar to the following:

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

To interact with the mail server, you can respond with the “ehlo” command, followed by your sender domain name. For example:

ehlo mydomain.tld

The mail server will then provide you with information about the supported methods and capabilities. The following is an example response:

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

To terminate the connection, enter the command “quit”. The server will respond with “221 2.0.0 Bye”, indicating that the connection has been closed. The complete command sequence would look like this:

user@server1:~# 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.
user@server1:~#

By utilizing Telnet to test your mail server, you can ensure that it is functioning correctly and properly responding to commands.

Conclusion

While Telnet is an outdated and insecure protocol, it still has some use cases for educational purposes and testing specific services like mail servers. In this tutorial, we covered the installation and usage of Telnet on an Ubuntu 22.04 LTS server. We also demonstrated how to test the Telnet connection from a remote system, check open ports, and test a mail server using Telnet. Remember, it is crucial to prioritize security and use more secure protocols like SSH for managing your servers. If you require reliable and secure hosting solutions, consider Shape.host’s Linux SSD VPS services, which offer efficient and scalable cloud hosting options.