Jannah Theme License is not validated, Go to the theme options page to validate the license, You need a single license for each domain name.
Linux

How to Use Telnet Command in Linux with Examples?

Introduction

Telnet, a timeless and versatile networking tool, has been a staple in the world of network administration and troubleshooting. In the Linux environment, mastering the telnet command can empower users to establish connections, diagnose network issues, and interact with remote servers efficiently. In this guide, we’ll delve into the intricacies of the telnet command in Linux, exploring its various applications and providing hands-on examples.

What is Telnet Command?

What is Telnet Command?

The Telnet command, a stalwart in the realm of networking tools, performs a pivotal element in operating communication between devices over a network. Specifically designed for text-based communication, Telnet is instrumental in establishing connections to remote servers, executing commands, and diagnosing network issues. In the Linux environment, the telnet command is a versatile utility that empowers users to interact with other systems seamlessly.

Key Components of the Telnet Command:

Establishing Connections:

The telnet command in Linux is primarily used for initiating connections to remote servers. By specifying the target server’s hostname or IP address, users can seamlessly establish a link to access resources or troubleshoot network-related challenges. The simplicity of the command lies in its fundamental structure:

telnet [hostname or IP address] [port]
Key Components of the Telnet Command

Port Specification:

Telnet supports the connection to specific ports on remote servers. While the default port is 23, users can specify an alternative port by including it in the command. This flexibility is crucial when interacting with various services hosted on a server. For instance:

telnet example.com 8080
Key Components of the Telnet Command

This command establishes a connection to port 8080 on the server named “example.com.”

Checking Port Status:

An invaluable feature of the telnet command is its ability to check the status of ports on remote servers. This functionality aids in diagnosing network issues by verifying the accessibility of a specific port. A typical command for this purpose is:

telnet example.com 22
Key Components of the Telnet Command

In this example, the command checks whether port 22, commonly used for SSH, is open on the server.

How to Install Telnet on Different Linux Distributions?

Telnet, being an essential networking tool, is an effective add-on to any Linux system. Installing Telnet is a straightforward process, but the process can little different according to the Linux distribution in use. In this section, we’ll explore how to install Telnet on two popular families of Linux distributions: CentOS, Fedora, and RHEL, as well as Ubuntu and Debian-based distributions.

– CentOS, Fedora, and RHEL

For users of CentOS, Fedora, and Red Hat Enterprise Linux (RHEL), Telnet can be installed using the package manager, which is yum or dnf depending on the distribution version.

Open a terminal & employ the following command:

sudo yum install telnet  # For CentOS/RHEL 6 and earlier
How to Install Telnet on Different Linux Distributions
sudo dnf install telnet  # For Fedora, CentOS/RHEL 7 and later

This command will fetch the Telnet package from the official repositories and install it on your system.

– Ubuntu and Debian-Based Distributions

Ubuntu, Debian, and their derivatives use the apt package manager for installations.

Open a terminal and employ the given below command:

sudo apt-get update
How to Install Telnet on Different Linux Distributions
sudo apt-get install telnet
How to Install Telnet on Different Linux Distributions

The first command assures that your package list is up to date, and the second command installs Telnet on your system.

Verifying the Installation:

To confirm that Telnet has been effectively installed, you can employ the given below command:

telnet --version

This will show data about the installed Telnet version.

Uninstalling Telnet:

If, for any reason, you need to uninstall Telnet, you can use the package manager’s remove command.

For CentOS, Fedora, and RHEL:

sudo yum remove telnet  # For CentOS/RHEL 6 and earlier

or

sudo dnf remove telnet  # For Fedora, CentOS/RHEL 7 and later

For Ubuntu and Debian-based distributions:

sudo apt-get remove telnet
Ubuntu and Debian-Based Distributions

Remember that having Telnet installed introduces security considerations due to its text-based nature. If security is a concern, consider using SSH (Secure Shell) for secure remote connections instead.

How to Use Telnet in Linux?

How to Use Telnet in Linux?

Telnet, a timeless command-line tool, remains an indispensable asset in the toolkit of Linux users, network administrators, and system troubleshooters. In this guide, we’ll delve into the various applications of the telnet command in Linux, demonstrating its versatility in checking for open ports, downloading web pages to files, testing SMTP communication, and connecting to remote systems.

– Check for Open Ports

One of the primary use cases of the telnet command in Linux is checking for open ports on a remote server. This capability is invaluable for diagnosing network issues and ensuring that specific services are accessible.

For checking whether a port is open, utilize the given below syntax:

telnet [hostname or IP address] [port]
How to Use Telnet in Linux?

For instance, for checking if port 80 (HTTP) is open on a server:

telnet example.com 22

If the connection is successful, you’ll see a response from the server. If the port is closed or the server is unreachable, you’ll receive an error message. This simple yet effective test can help identify connectivity problems and streamline the troubleshooting process.

– Download Web Page to File

Telnet can also be used to fetch the contents of a web page and save it to a file. This is particularly useful for quick checks or when a graphical web browser is not available.

Here’s an example of how to download the HTML content of a web page to a file:

(echo "GET / HTTP/1.0"; echo) | telnet example.com 80 > webpage.html

In this command:

How to Use Telnet in Linux?

(echo “GET / HTTP/1.0”; echo) sends an HTTP GET request to the server.

telnet example.com 80 establishes a connection to the web server.

> webpage.html redirects the server’s response to a file named webpage.html.

This method provides a raw representation of the web page’s HTML, which can be useful for further analysis or documentation.

– Test SMTP Communication

Telnet is a valuable tool for testing Simple Mail Transfer Protocol (SMTP) communication, allowing you to troubleshoot email-related issues or simply understand how email servers interact.

To test an SMTP server, connect to it using the telnet command. For example, to connect to the SMTP server at mail.example.com on port 25:

telnet mail.example.com 25
How to Use Telnet in Linux?

Once connected, you can simulate an email conversation with the server. Start by initiating the SMTP conversation:

EHLO example.com

Followed by:

MAIL FROM: [email protected]

And:

RCPT TO: [email protected]

Finally, to send the email body:

DATA

Subject: Test Email

This is a test email.

.

The . on a line by itself signifies the end of the email body. This interactive SMTP session allows you to verify the responsiveness of the SMTP server and troubleshoot any issues.

– Connect to Remote System

Telnet’s ability to establish interactive sessions with remote systems makes it a valuable tool for remote administration and troubleshooting. To connect to a remote system, use the following syntax:

telnet [hostname or IP address]
How to Use Telnet in Linux?

For example:

telnet remote.example.com

Once connected, you can input commands directly into the terminal, providing a text-based interface to the remote system.

Also Read: Steps to Unzip/Extract tar.gz Files in Linux Using Command Line

Conclusion

In the dynamic realm of Linux networking, the telnet command emerges as a versatile ally, connecting administrators with remote systems seamlessly. Our journey through this guide showcased Telnet’s prowess in checking open ports, conducting interactive sessions, and simulating communication with various services.

Telnet’s simplicity, with commands like telnet [hostname] [port], belies its complexity. It becomes a diagnostic powerhouse, swiftly identifying network issues and facilitating efficient troubleshooting. Whether downloading web pages, testing SMTP, or establishing remote sessions, telnet proves its adaptability.

Installation, consistent across distributions, ensures universal accessibility. However, security-conscious users are reminded to consider alternatives like SSH for encrypted connections.

As we conclude, telnet remains a timeless companion in Linux administration. It isn’t just a command; it’s a guide through the intricacies of Linux networking, empowering users to navigate with confidence and proficiency in an ever-evolving landscape.

Arpit Saini

He is the Director of Cloud Operations at Serverwala and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles