The telnet command in Linux allows you to establish connections between machines and remotely access them through a command line interface (CLI). In this comprehensive guide, we‘ll cover everything you need to know about using telnet on Linux systems.

What is Telnet?

Telnet is a network protocol that provides bidirectional interactive text-oriented communication using a virtual terminal connection. When you use the telnet client application, it connects to the TCP port 23 of a remote host where a telnet server is listening. This allows you to execute commands and run programs on the remote machine from your local terminal.

Some key things to know about telnet:

  • Communication is done in plain text without encryption
  • Uses TCP port 23 by default
  • Allows remote command execution through CLI
  • Provides interactive terminal access
  • Has client-server architecture

In Linux, telnet is handy for testing connectivity between machines, remotely configuring network devices, accessing text-based interfaces without GUI, and administration purposes.

Installing the Telnet Client

Most Linux distributions don‘t come with the telnet client installed by default. Here are the commands to install it:

Debian/Ubuntu

sudo apt update
sudo apt install telnet

RHEL/CentOS

sudo yum update 
sudo yum install telnet

Fedora

sudo dnf update
sudo dnf install telnet

Arch Linux

sudo pacman -Syu
sudo pacman -S telnet

This will install the telnet client application along with the supporting telnetd server package on your system.

Checking the Telnet Service Status

By default, the telnet server may be disabled on your Linux distribution. You can check its status with:

sudo systemctl status telnet.socket

To enable telnetd server on system startup:

sudo systemctl enable telnet.socket

Start the telnet service:

sudo systemctl start telnet.socket

Now verify that it shows active (listening) state.

Additionally, you need to allow TCP port 23 traffic if using firewalls like firewalld or ufw.

Using the telnet Command

The basic syntax for using telnet client is:

telnet [options] <host> <port>

Some common options are:

  • -a – attempts automatic login
  • -l – specifies username for login
  • -t – sets telnet in linemode (for ssh tunnels)

So to connect to a remote system named server1 on standard telnet port 23, you would run:

telnet server1

This will interactively prompt you for the remote server login and password.

Alternatively, provide this info directly:

telnet -l admin server1  

After successful authentication, you will be presented with the terminal of the remote host. Now you can execute system commands and run programs as if working locally.

For example, running uname -a displays kernel info of the remote machine instead of local system details.

To exit the remote telnet session, use the quit or logout command at any time.

Telnet vs SSH

Telnet has some similarities with SSH but there are important security differences:

Telnet

  • Communication in plain text
  • No encryption
  • Credentials transmitted unencrypted
  • Prone to eavesdropping and MITM attacks

SSH

  • Encrypted sessions
  • Secure channel for data transfer
  • Encrypted authentication
  • Protection against cyberattacks

As you can see, telnet is fundamentally less secure compared to SSH. While SSH encrypts the entire session, telnet has no encryption at all making it risky for logging into remote machines across public networks.

Using Telnet for Testing Connectivity

While telnet might not be advisable for remotely accessing production machines due to security issues, it is still very useful for testing basic TCP connectivity issues between networked devices.

This allows checking if you can reach another system at all – verifying routes and firewall configurations.

Some examples for testing connectivity over telnet:

$ telnet webserver.example.com 23
$ telnet 192.168.1.10 23 
$ telnet cloudserver 23

If telnet is able to open a connection to the destination system on port 23, then the basic network connectivity is working fine between the source and target hosts.

For debugging purposes, this is more helpful than ping testing alone since it specifically checks the state of port 23 which telnet depends on.

Automating Telnet Sessions

While performing one-off administrating tasks on remote systems using interactive telnet sessions is handy, you can also automate this process with scripting.

Expect scripting language can be used to script automated telnet sessions.

Here is a simple expect script example that connects to a device, runs some commands and logs out:

spawn telnet 192.168.5.1 
expect "Password:"
send "pa55w0rd\r"
expect "#"  
send "enable\r"
expect "#"
send "terminal length 0\r" 
send "show ver\r"
send "logout\r"  
expect eof

The script spawns the telnet process, waits for password prompt, enters password, waits for command prompt # and then runs the show ver command to display device firmware info. Finally, it exits the session.

This script can be now executed directly:

expect telnet-session.exp

By using expect, you can easily automate mundane tasks over telnet in a efficient manner.

Telnet Alternatives

Here some alternatives to using telnet:

  • SSH – Provides secure encrypted connections to remote machines.
  • Web Terminal – Access command line interface through web browsers.
  • Remote Desktop Software – GUI based remote access with more features. Options like VNC allow accessing full remote desktop environment graphically.

Wrapping Up

The telnet client remains a simple and usually pre-installed tool on Linux for interactively running commands on remote systems through a text terminal. While it lacks encryption offered by ssh, telnet is still very handy for network connectivity troubleshooting, quickly testing client-server apps, accessing text-mode interfaces without GUIs and similar admin tasks with legacy systems. For scripted access, solutions like expect further automate telnet system interaction.

Overall while telnet is not always secure enough for production systems facing public networks, it still is ubiquitously available on almost all distributions of Linux. For users on tightly controlled private LAN environments, telnet continues to provide easy terminal level access to networked machines.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *