Friday, March 1, 2024
HomeHow toHow to Install and Use Telnet on Ubuntu 22.04 LTS

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. For example, a Telnet client is a useful tool for testing your mail or web server, 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:

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:~#

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.

Frequently Asked Questions

What is Telnet?

Telnet is a network protocol used to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection. It’s commonly used for accessing remote servers.

Is Telnet secure for transferring sensitive data?

No, Telnet is not secure for transferring sensitive data because it transmits data in plain text. For secure communications, SSH (Secure Shell) is recommended.

How do I use Telnet on Ubuntu?

To use Telnet, open your terminal and type:

telnet [hostname] [port]

Replace [hostname] with the IP address or domain of the server you want to connect to, and [port] with the port number.

Can I install Telnet on all versions of Ubuntu?

You can install Telnet on all current versions of Ubuntu. However, ensure your system is up to date before installing new software.

Why do I get an error message when trying to install Telnet?

If you receive an error message, it might be due to several reasons such as your system not being updated, or the Telnet package not being available in your repository. Ensure your system is up to date and you have an active internet connection.

How do I uninstall Telnet from Ubuntu?

To uninstall Telnet, open your terminal and type

sudo apt-get remove telnet

Are there alternatives to Telnet for Ubuntu?

SSH is a popular alternative to Telnet. It provides encrypted connections and is more secure. Install SSH by typing `sudo apt-get install openssh-client` in your terminal.

Can I use Telnet to connect to Windows servers from Ubuntu?

Yes, you can use Telnet to connect to Windows servers if Telnet services are enabled on the Windows server.

Is it possible to automate tasks using Telnet in Ubuntu?

While it is technically possible to automate tasks using Telnet scripts, it is not recommended due to security risks. Consider using more secure methods like SSH for automation.

What is the purpose of testing a mail server using Telnet?

Testing a mail server using Telnet allows you to manually send email messages, check for open SMTP ports, and diagnose issues with the mail server’s operation. This can be useful for troubleshooting email delivery problems.

What should I do if the Telnet connection to the mail server fails?

If the connection fails, check if the mail server address and port number are correct. Also, ensure that your network allows outbound connections on port 25. Some ISPs block this port due to security reasons.

How do I send an email using Telnet?

After connecting to the SMTP server via Telnet, use the following commands in order:

HELO [your_domain.com]
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA

Then, type your message. When finished, end the message with a single period (.) on a new line and press Enter.
Finally, use the QUIT command to end the session.

What are common errors to look out for when testing a mail server with Telnet?

Common errors include connection timeouts, refusal errors, or error codes from the SMTP server such as 550 (user not found) or 451 (temporary local problem). These indicate issues with server accessibility or email delivery.

Is it possible to test secure SMTP ports using Telnet?

Telnet does not natively support encrypted connections (like those used on ports 465 or 587 for secure SMTP). For testing these, tools like OpenSSL are more appropriate.

Can I use Telnet to test IMAP or POP3 mail server ports?

Yes, you can use Telnet to connect to IMAP (port 143 or 993) or POP3 (port 110 or 995) servers. However, remember that commands and interactions differ from SMTP.

Do I need special permissions on Ubuntu to use Telnet for testing mail servers?

No special permissions are needed to use Telnet; however, you do need network access and the right to install Telnet if it’s not already present on your system.

How do I interpret the responses from the mail server during a Telnet session?

SMTP responses are typically numerical codes followed by a text message. Codes beginning with 2 indicate success, 4 indicate temporary failures, and 5 indicate permanent failures. The text message provides more detail about the response.

Is testing a mail server with Telnet a secure method?

Testing with Telnet is not encrypted, making it insecure for transmitting sensitive information. It’s generally used for troubleshooting in controlled environments. For secure communication, use protocols like SSH.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here


spot_img

Most Popular