How to Install and Use Telnet on Linux

telnet [options] host [port] on light blue background

Telnet is a protocol that is used to communicate two-way texts over a network. This protocol was developed intending to communicate texts that could work as interactive commands to control/operate a remote machine.

In recent times, telnet has been obsoleted by SSH (Secure Shell) which encrypts the communications.

Telnet generally comes pre-installed in Windows operating systems. Let’s see how we can install it on Linux machines and use it.

Install Telnet on Linux

Telnet is available in the repositories for you to install from Linux command line. Use your package installer to install it. For Debian based Linux use the following command:

sudo apt-get install telnet telnet-server

In CentOS/Rocky Linux/AlmaLinux or other RedHat distros, use the yum command:

yum install telnet telnet-server -y

Telnet Installation: Should I Install Server or Client?

We are installing telnet and telnet-server both packages in the previous commands.

The package telnet is the client, and the telnet-server package will run a service and let us connect to it, thus it will be a server. We are installing telnet-server for demonstration purposes.

If we already had a machine with telnet server installed to it, then we would not require telnet-server in our machine to connect to it. Installation process may vary according to repositories and distros of the Linux that you are running. I will show my procedures here just so you know how it goes (I’m running a Debian based Linux distro):

First, I updated my package lists by using the apt update command:

sudo get update

After that, I used the install command to install both packages:

sudo apt install telnet telnet-server
Output
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package telnet-server is a virtual package provided by:
  telnetd-ssl 0.17.40+0.2-1
  telnetd 0.17-40
  inetutils-telnetd 2:1.9.4-1build1
You should explicitly select one to install.

As you can see from the output of the command, we are told to specify which package to install since there are multiple options (highlighted in green). So, I chose “telnetd” to install as my telnet server. I typed in the following command:

sudo apt install telnet telnetd

I was prompted to type y or n confirming if I wanted to install. I typed y and the installations proceeded normally.

We installed telnetd package. Notice that we haven’t installed telnet package yet because of that multiple matching packages in the output. Now we will install telnet and another package called xinetd using the following command:

sudo apt install telnet xinetd

Now that we know how to install the telnet packages (both client & server), let’s see how we can use them.

Telnet Server: Configure the Server

After installing those server packages, we must configure them so that we can connect to it. First, we will start by configuring the inetd.conf file located at /etc/inetd.conf:

sudo nano /etc/inetd.conf

Now scroll down until you find the lines below:

#:STANDARD: These are standard services.
telnet stream tcp nowait telnetdt /usr/sbin/tcpd /usr/sbin/in.te

Replace the highlighted line with the following:

telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd

Now let’s configure the xientd.conf:

sudo nano /etc/inetd.conf

Replace the whole content of the file with the following texts:

# Simple configuration file for xinetd
#
# Some defaults, and include /etc/xinetd.d/
defaults
{
# Please note that you need a log_type line to be able to use log_on_success
# and log_on_failure. The default is the following :
# log_type = SYSLOG daemon info
instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
cps = 25 30
}

Now we will create a new configuration file called telnet in the /etc/xinetd.d/ location:

sudo nano /etc/xinetd.d/telnet

Copy and paste the following configurations into the text:

# default: on
# description: The telnet server serves telnet sessions; it uses
# unencrypted username/password pairs for authentication.
service telnet
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}

Check if the file was created:

ls -la /etc/xinetd.d/
Output
total 12
drwxr-xr-x 1 root root 512 Jun  1 20:53 .
drwxr-xr-x 1 root root 512 Jun  1 20:50 ..
-rw-r--r-- 1 root root 640 Oct 26  2013 chargen
-rw-r--r-- 1 root root 502 Oct 26  2013 daytime
-rw-r--r-- 1 root root 391 Oct 26  2013 discard
-rw-r--r-- 1 root root 422 Oct 26  2013 echo
-rw-r--r-- 1 root root 281 Jun  1 20:53 telnet
-rw-r--r-- 1 root root 569 Oct 26  2013 time

Using Telnet To Connect With the Configured Server

We have spent quite a lot of time installing and configuring our telnet server. Now that we have the server configured, it’s time to connect to it.

First, we will restart the xinetd service. Type in the following command:

sudo service xinetd restart
Output
* Stopping internet superserver xinetd [ OK ]
* Starting internet superserver xinetd [ OK ]

Connecting to Your Own Machine Using Telnet

Let’s find out the IP address of our machine now. We will use ifconfig command to do that:

ifconfig
Output
wifi0     Link encap:UNSPEC  HWaddr 10-02-B5-99-C2-A3-00-00-00-00-00-00-00-00-00-00
          inet addr:192.168.0.110  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Your output may contain many different interfaces. It’s important to get the IP address of the interface that you are using for connecting to the internet. Since I am using Wi-Fi to connect to the internet, I only looked at the IP address of wifi0 interface. Now let’s try connecting to 192.168.0.110 using telnet:

telnet 192.168.0.110
Output
Trying 192.168.0.110...
Connected to 192.168.0.110.
Escape character is '^]'.
Ubuntu 16.04.2 LTS
DESKTOP-G8 login: fenics
Password:
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-17134-Microsoft x86_64)

fenics@DESKTOP-G8:~$

As you can see, we have now connected to the IP address of the telnet server with our telnet client.

We also received the terminal of the machine from telnet. Now we can execute any commands that we would like.

Now let’s try to connect from another machine that is in our local network.

Connecting to the Telnet Server From Another Machine on Local Network

So far, we have created a telnet server on our Debian/Ubuntu Linux machine and connected to that server from the same Linux machine.

Now, I am going to connect to the server using a different machine in my local network. You can also do this experiment if you have another local machine (preferably Windows, Linux will also work but you will need to install telnet client first). However, you may need to enable port forwarding in your router. In my case, my main operating system is Windows 10.

I have a virtual Linux machine/bash on which I installed the telnet server. Now let’s connect from my Windows to the Linux using telnet.

On my Windows machine, telnet client is enabled. If it not enabled in your Windows, go to Control Panel > Programs > Turn windows feature on or off, and check the box of Telnet client. Now, type in:

telnet 192.168.0.110
Output
Ubuntu 16.04.2 LTS
DESKTOP-G8 login: fenics
Password:

Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-17134-Microsoft x86_64)


fenics@DESKTOP-G8:~$ ls
dir1  dir2  file  file.txt  new_file.txt  newfile  num.txt  tutorial.firstpage.php  undergrad_buet.pdf

fenics@DESKTOP-G8:~$

As you can see, I got the Linux shell from my Windows machine. I can execute commands on my Linux virtual machine from Windows using telnet.

Telnet Command Uses

Earlier we showed you the main function of telnet – connecting two machines over text communication. Now let’s see what we can do with telnet as a command.

You can either use telnet with direct command in a single line. For example:

telnet 192.168.0.110

There is also another option where you can use telnet interactively. To do that, type in telnet and hit enter:

telnet
Output
telnet>

Let’s see the help to learn more about the command. Type in h and hit enter in interactive mode:

telnet> h
Output
telnet> h

Commands may be abbreviated.  Commands are:

close           close current connection
logout          forcibly logout remote user and close the connection
display         display operating parameters
mode            try to enter line or character mode ('mode ?' for more)
open            connect to a site
quit            exit telnet
send            transmit special characters ('send ?' for more)
set             set operating parameters ('set ?' for more)
unset           unset operating parameters ('unset ?' for more)
status          print status information
toggle          toggle operating parameters ('toggle ?' for more)
slc             set treatment of special characters
z               suspend telnet
environ         change environment variables ('environ ?' for more)

From the help menu, we can see that if you use open command in interactive mode, telnet will connect to a site/device. Now, you can type in open followed by the IP address to perform the same thing as shown in the previous case:

telnet> open 192.168.0.110
Output
Trying 192.168.0.110...
Connected to 192.168.0.110.
Escape character is '^]'.
Ubuntu 16.04.2 LTS
DESKTOP-G38 login:

The rest of the commands are well explained in the help menu. You can also get further help for one of those commands following the help information. For example, if you type in set ? and hit enter, the terminal will show you help for set command.

Conclusion

In this tutorial, we learned how to install and use telnet client as well as telnet server in Linux. We installed telnet server, then configured it. After configuration we connected to the server from local machines using telnet client.

The process illustrated here mostly applies to Debian based distros such as Ubuntu. However, you may try in other Linux distributions in the same way described to see if it works.

If you face any issues, feel free to leave a comment and we will get back to you as soon as possible. Thank you for reading.

 

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
William B Peckham
William B Peckham
1 year ago

I had expected something covering more Linux distributions, this only covers a small (though significant) subset. None of these instructions work outside of the Debian/Ubunti (apt) and RHEL (yum) universe, and some of the RHEL commands are depreciated on the latest versions. Even where the commands work, the package names may be different! ARCH based distributions do not natively support either APT or YUM, and the rempos do not contain packages using those names. I suggest either adjusting the title, or presenting a more comprehensive discussion with disclaimers about what is NOT covered!

You May Also Like