3v-Hosting Blog

The Telnet Command and Its Use in Linux

Administration

9 min read


Though largely replaced in modern environments by more secure alternatives, such as SSH, the telnet command remains a versatile and lightweight tool for checking basic network connectivity, troubleshooting TCP-based services, and testing simple interactions with remote services. In the Linux ecosystem, Telnet serves as a quick way to open TCP connections and observe raw protocol communications between a client and a server.

Despite its historical roots, telnet is still useful for system administrators, developers, and network engineers who need to understand how network services behave at a low level. This article explores the fundamental concepts behind Telnet, its use in Linux environments, common use cases, and important caveats surrounding its use in modern systems.

 

 

 

 

Understanding Telnet: A Brief Overview

 

Telnet, short for "Teletype Network," is one of the earliest remote access protocols developed for TCP/IP networks. Its primary purpose is to provide command-line access to remote systems. Telnet operates over TCP port 23 by default and allows users to interact with remote machines via a virtual terminal interface.

However, Telnet transmits data in plain text, including authentication credentials, making it insecure for most modern applications. For this reason, Telnet has been replaced for remote logins by SSH, which encrypts all communications. Nevertheless, the Telnet command remains available on many Linux distributions as a basic TCP client, offering diagnostic capabilities for network services that SSH cannot easily replicate.

 

 

 

 

Installing Telnet on Linux

 

Most modern Linux distributions do not include telnet by default due to security concerns. However, installing it is straightforward:


On Debian/Ubuntu-based systems:

    sudo apt update
    sudo apt install telnet


On RHEL/CentOS/Fedora:

    sudo dnf install telnet

Once installed, the telnet binary becomes available in the system path, typically as /usr/bin/telnet.

 

 

 

 

Basic Telnet Syntax and Usage

 

The general telnet syntax is as follows:

    telnet [host] [port]

For example, to check whether port 80 is open on a web server:

    telnet example.com 80

If the connection is successful, the terminal will switch into an interactive mode where the user can type HTTP requests manually. This is extremely useful when verifying if a web server responds as expected.

 

Here is a telnet command example that issues a basic HTTP request:

    telnet example.com 80
    GET / HTTP/1.1
    Host: example.com

Notice that the blank line at the end is required to complete the HTTP request. The server should respond with raw HTTP headers and content, offering insights into its configuration.

This example shows the real power of telnet-it is not bound to a specific application protocol. Instead, it allows raw TCP interaction, making it ideal for testing any TCP-based service, including SMTP, POP3, FTP, Redis, and even custom services.

 

 

 

 

Practical Use Cases for Telnet in Linux

 

1. Port Connectivity Testing

One of the most common uses of telnet is to verify whether a specific port on a remote host is accessible. This is especially useful when debugging firewall or NAT issues.

Example:

    telnet 192.168.1.100 22

If you see a "Connected" message, the port is open. If you get "Connection refused" or "Connection timed out", the port is either closed or blocked.


2. Testing Mail Servers (SMTP)

Telnet is often used to simulate sending an email manually via SMTP for troubleshooting or educational purposes.

    telnet mail.example.com 25

Followed by:

    HELO test.local
    MAIL FROM:<test@example.com>
    RCPT TO:<admin@example.com>
    DATA
    Subject: Test mail

    This is a test message.
    .
    QUIT


3. Debugging FTP or Other Protocols

Similarly, you can test whether an FTP server or another custom TCP service is working correctly.

    telnet ftp.example.com 21

The response will typically start with:

    220 (vsFTPd 3.0.3)


4. Redis or Memcached Testing

Since these in-memory databases often listen on open TCP ports, telnet can be used to test basic commands.

    telnet localhost 6379

Then type:

    PING

Expect:

    +PONG

 


 

Other articles on Linux in our Blog:


    - How to Use the Linux find Command

    - The 405 error and how to fix it

    - Configuring Access to the Server by SSH Key

    - 10 useful console utilities for monitoring a Linux server

 


 

 

Telnet Session Controls and Special Commands

 

During an active session, telnet supports escape characters and session commands. By default, Ctrl+] drops you into the telnet command mode, where you can type various telnet commands like:

    quit: exit the session
    send ao: abort output
    status: check current connection status
    open host port: open a new connection
    ? or help: display available commands (known as telnet help)

These control features allow you to manage multiple sessions or diagnose behavior without killing the terminal process.

 

 

 

 

Security Implications of Using Telnet

 

Since Telnet does not encrypt traffic, using it over untrusted networks poses a significant security risk. Any transmitted data, including login credentials and session contents, can be intercepted by attackers using packet sniffing tools like Wireshark.

Therefore, the Telnet command in Linux should never be used to authenticate to remote systems unless it is on a secured, isolated network. In public or production environments, use SSH instead.

Even when using Telnet strictly for testing, ensure that the destination service cannot be exploited or crashed by malformed input, especially if it is running on legacy software.

 

 

 

 

Telnet in Scripts and Automation

 

Although telnet is primarily an interactive tool, it can be used in simple scripts using tools like expect, which allows automating interactions.

Example of using telnet with expect:

    #!/usr/bin/expect
    spawn telnet example.com 23
    expect "login:"
    send "myuser\r"
    expect "Password:"
    send "mypassword\r"
    interact

This is useful for legacy systems that still rely on Telnet for access. But again, caution is warranted due to the insecure nature of the protocol.

 

 

 

 

Comparing Telnet on Linux vs. Windows

 

On Windows, the telnet client is disabled by default in recent versions (such as Windows 10/11), but it can be enabled via:

    Control Panel → Programs and Features → Turn Windows features on or off → Telnet Client


Once enabled, you can run telnet from the cmd prompt using the same syntax:

    telnet example.com 80

This is referred to as the cmd telnet method and functions similarly to Linux. However, Windows offers less flexibility in terms of scripting and session handling.

In both systems, users can type telnet /? to get built-in telnet help, though it's more limited in Windows.

 

 

 

 

Alternatives to Telnet

 

In today’s secure environments, telnet is often replaced by:

    nc (netcat): Similar in purpose but more scriptable and flexible.
    curl or wget: For interacting with HTTP services.
    ssh: For secure terminal access.
    nmap: For detailed port scanning.

Yet, telnet remains relevant when simplicity, raw access, or a quick connectivity test is the goal.

 

 

 

 

Conclusion

Despite its age and well-known security vulnerabilities, the Telnet command remains a valuable tool for system administrators and network engineers. It excels at quick and dirty diagnostics, raw protocol testing, and educational contexts that require visibility into data streams.

Whether you're simulating an SMTP conversation, testing TCP port availability, or observing service behavior, Telnet provides an unbeatable, no-frills approach. While it's not suited for production use due to security risks, understanding its functionality is essential for professionals managing or troubleshooting networked systems.