Use Telnet Command on Linux 1

How to Use Telnet Command on Linux

The Telnet command protocol is used on Linux in connecting systems through a command-line interface. Similar to SSH, Telnet is also used to manage systems. It was created by Microsoft. You can easily learn how to use telnet commands on Linux machines.

The telnet protocol was widely used before SSH became mainstream. SSH provides a secure shell connection. On the other hand, the Telnet protocol lacks secure encryption. Users use this protocol widely because of its simple communication process. 

In this article, you will learn how to install and use telnet commands on Linux to communicate over the network.

Syntax of Telnet Command

To use the telnet protocol on Linux machines, use the telnet command. The general syntax of the command is:

telnet [-468EKLadr] [-Xa authtype] [-b hostalias] [-l user] [-n tracefile] [ host [port] ] 

At a glance, the syntax looks very complicated. Here is the breakdown of the syntax:

  • [-468EKLadr]: specifies the properties of the address to which we are connecting.
  • [-Xa authtype]: specifies the type of authentication used in the connection.
  • [-b hostalias]: lists the host alias.
  • [-l user]: sends the user to the remote server.
  • [-n tracefile]: traces the file operations.
  • [ host [port] ]: specifies the host to which we are connecting and the port number we are using for the connection.

However, the only mandatory parameters are the hostname and port number from this list of the parameters.

Prerequisite

For this tutorial, you will need a root account or a machine with sudo privilege. You do not require Telnet protocol at this stage.

Use Telnet Command on Linux

Since telnet protocol does not provide encryption by default, hence it is not recommended to use it for exchanging sensitive data. Also, hackers can can easily sniff data which makes it insecure. However, for the learning purpose, the article covers a detailed guide on how to install and use the telnet protocol using the telnet command. Keep reading and learn the exact approach.

1. Update the System

Before installing the telnet protocol, it is crucial to update the existing packages. Open the terminal using the shortcut key “Ctrl + Alt + T”. Then, type the command given below to update the system:

sudo apt update

You will get a similar output:

Use the Telnet Command on Linux

2. Install the Telnet command on Linux

To install the Telnet command on AlmaLinux, Rocky Linux, CentOS, or Fedora, use the yum command. For example: 

# sudo yum -y install telnet

Use the telnet command to ensure that telnet is working. Specifically, type: 

# telnet localhost 22
telnet2

For Ubuntu, use the apt package to install the telnet protocol. For instance, type: 

sudo apt install telnet

If you get a similar output, that means the telnet is already installed on your system.

Install the Telnet Command

After successfully installing the command, we will install the Telnet server. The telnet server is used to connect to the Telnet clients. To install the server, type the following command:

sudo apt install telnetd -y  

Your output would look something like this:

Install the Telnet Server

To verify the installation, execute the telnet2 command. For example:

telnet2 –version

Now to verify that the service is up and running, use the systemctl command. Specifically, type: 

systemctl status inetd  

Hit the “Enter key” and you will get this output: 

Start Telnet Service

3. Open Firewall for the Telnet Port

Since Telnet uses ports 22 and 23, we will allow these ports on the ufw firewall. For this step, execute the following command: 

sudo ufw allow 23/tcp  

Your output would look something like this:

Use the Telnet Command

Alternatively, you can also use the telnet keyword. For example:

sudo ufw allow telnet 

Next, reload the firewall to implement the changes. To reload the ufw firewall, type:

sudo ufw reload  

Finally, you have successfully installed the telnet protocol. Now, you are ready to use the telnet command on Linux. 

4. Start the Telnet Shell

To start the telnet shell, type:

telnet  

You will get a similar output:

Open Telnet Server

This command will open a list of commands exclusive to telnet. Alternatively, you can also view the telnet command details by typing:

man telnet
telnet –help

You will get a similar output:

Telnet Help

Both commands will list down all the requirements for the telnet command and the options you can use with it. 

5. Connect Using Telnet Command

We will use the telnet command to connect to a remote system or localhost. For example: 

telnet localhost  

After the execution of this command, you will be asked to enter your username and password. Type the credentials, and hit the “Enter key” to continue. 

The output would look something like this:

Telnet Localhost

After the successful connection, the localhost will behave as a remote server and you can run all the telnet commands. 

6. Create a Telnet User

To create a telnet user, execute the command given below:

sudo adduser telnetuser

To create the password, type: 

sudo passwd telnetuser

Specify the password and confirm.

After the creation of a user, you can log in to any server using the IP address. 

You can also connect to the telnet using PuTTy. Make sure to check the ‘Telnet’ radio button at the time of connection. 

Telnet Connection

7. Check for Open Ports Using Telnet

Through Telnet, you cannot only communicate with the server, but you can also check the open ports on that server. For this step, the syntax is shown below:

telnet server-IP port

For example:

telnet 38.76.11.19 22

8. Exit from the Telnet Server

To logout from the telnet shell, execute the following command: 

logout  

Alternatively, you can also use the close command. For example:

close

You have successfully logged out from the remote server. 

9. Exit the Telnet Shell

To exit from the telnet shell, use the following command: 

quit
Quit Telnet

You will successfully exit from the running telnet shell. 

And that is a wrap on the telnet command! 

The telnet command is widely used for communication because of its simple mechanism. It is similar to the SSH protocol, but it does not provide encryption to the data. In this article, you have learned how to use the telnet command for a simple remote connection. We hope the article was useful to you. We hope you found this article to be useful. 

If this guide helped you, please share it.

Leave a Reply
Related Posts