Telnet is a network protocol used for connecting to remote systems through a command-line interface. It can be used to configure remote devices such as routers, switches, servers, etc. Telnet can also be used to test if a TCP port on a remote system is open or not.
Note: Telnet is not a secure protocol because the Telnet session between server and client is unencrypted. You can use it for testing the connectivity to TCP ports. However, for connecting to the remote system, it is recommended to use SSH.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Telnet configuration queries.
In this context, we shall look into how to install the Telnet server and client on Ubuntu 20.04 LTS.
Here, we will use two Ubuntu 20.04 LTS machines. On one Ubuntu machine, we will install Telnet server. On another Ubuntu machine, we will install the Telnet client. Then we will connect to the Telnet server using the Telnet client.
Ubuntu default repository contains the Telnet server package. Therefore, it can be simply installed with the apt command. On one Ubuntu machine, install Telnet server by running the command below in the Terminal:
$ sudo apt install telnetd xinetd
After running the above installation command, Terminal might prompt you with the y/n option. To continue the procedure, hit y and then hit Enter. It will then install the Telnet server and xinetd on your Ubuntu system.
After installation, the xinetd service starts automatically. You can view the status of the service as follows:
$ sudo systemctl status xinetd.service
If the service does not start automatically, you can manually start it by running the command below:
$ sudo systemctl start xinetd.service
Now create the /etc/xinetd.d/telnet file using the command below:
$ sudo nano /etc/xinetd.d/telnet
Add the below lines the file:
service telnet
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}
Then save and close the file and restart xinetd.service as follows:
$ sudo systemctl restart xinetd.service
Telnet server uses port 23 for listening to the incoming connections. Therefore, you will need to open this port in your firewall. Run the command below to do so:
$ sudo ufw allow 23
To allow incoming connections to port 23 from only a specific IP or subnet, run the below command instead:
$ sudo ufw allow from <ip or subnet> to any port 23
Telnet client is also available in the Ubuntu repository. On your second Ubuntu machine, run the command below in Terminal to install the Telnet client:
$ sudo apt install telnet
After running the above installation command, Terminal might prompt you with the y/n option.
To continue the procedure, hit y and then hit Enter. It will then install the Telnet client on your Ubuntu system.
Now you can connect to your Telnet server from another machine (where the Telnet client is installed). On your client machine, use the following command syntax to connect to the Telnet server:
$ telnet <server-ip>
Where <server-ip> is the IP address of the Telnet server.
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
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.
If for any reason you want to uninstall Telnet server and client from your Ubuntu machine, you can do so as described below.
To uninstall Telnet server, run this command:
$ sudo apt remove telnetd xinetd
To uninstall Telnet client, run this command:
$ sudo apt remove telnet
After running the above commands, Terminal might prompt you with the y/n option. To continue the procedure, hit y and then hit Enter.
It will then remove the applications from your Ubuntu system.
This article covers how you can easily install the Telnet server and client on your Ubuntu machines. In fact, Telnet is a command protocol that allows a user to connect to a remote host. It makes use of TCP/IP protocol to establish a connection with the remote computer.
The general format of the telnet command is:
telnet [hostname/ipaddress] [port number]
How to install telnet on AlmaLinux / Rocky Linux / CentOS / Fedora ?
Telnet command can be installed using YUM in all CentOS and Fedora distributions.
1. Execute the below command to install telnet:
# yum -y install telnet
2. Verify that the command is installed successfully:
# telnet localhost 22
How to install telnet on Ubuntu / Debian ?
Telnet command can be installed both in Ubuntu and Debian systems using the APT command.
1. Execute the below command to install telnet:
# apt-get install telnet
2. Verify that the command is installed successfully:
# telnet localhost 22