How To Use Telnet In Linux – Remote Server Connection Steps

Telnet in Linux connects to remote servers through port 23, though SSH is often preferred for security. If you need to know how to use telnet in linux for testing network services or troubleshooting legacy systems, this guide covers everything from installation to practical commands.

Telnet is a simple text-based protocol that lets you interact with remote computers. While it’s not encrypted and considered outdated for secure communication, it remains useful for checking open ports, testing SMTP or HTTP services, and accessing older equipment.

Let’s walk through the steps to install, configure, and use Telnet on your Linux system. You’ll learn the basic commands, common use cases, and security considerations.

What Is Telnet And Why Use It

Telnet stands for Teletype Network. It was developed in 1969 and allows users to log into remote systems over a network. The protocol sends all data in plain text, including usernames and passwords.

Despite its security flaws, Telnet is still valuable for:

  • Testing if a remote port is open and responsive
  • Debugging network services like web servers or email servers
  • Accessing older network hardware that only supports Telnet
  • Learning about network protocols manually

Many system administrators keep Telnet installed just for quick connectivity checks. It’s lightweight and doesn’t require complex configuration.

How To Install Telnet On Linux

Most Linux distributions don’t include Telnet by default. You need to install the telnet client package. The server package (telnetd) is separate if you want to accept incoming connections.

Installing Telnet On Debian Or Ubuntu

Use the apt package manager to install Telnet. Open a terminal and run:

sudo apt update
sudo apt install telnet

For the server component, add:

sudo apt install telnetd

Installing Telnet On Red Hat, CentOS, Or Fedora

On RPM-based systems, use yum or dnf:

sudo yum install telnet

Or for newer Fedora versions:

sudo dnf install telnet

To install the server:

sudo yum install telnet-server

Verifying The Installation

After installation, check if Telnet is available:

telnet --version

You should see version information. If not, double-check your package manager commands.

How To Use Telnet In Linux

Now that Telnet is installed, let’s look at the basic syntax and common commands. The general format is:

telnet [hostname or IP address] [port]

If you don’t specify a port, Telnet defaults to port 23. But you can connect to any TCP port for testing.

Connecting To A Remote Host

To connect to a server at 192.168.1.100 on port 23:

telnet 192.168.1.100

If the connection succeeds, you’ll see a login prompt. Enter your username and password (remember, they’re sent in plain text).

Connecting To A Specific Port

To test if port 80 (HTTP) is open on a web server:

telnet example.com 80

If the port is open, you’ll see a blank screen or a banner. You can then send HTTP requests manually.

Exiting A Telnet Session

To disconnect, press Ctrl + ] (control key plus right bracket). This opens the Telnet command prompt. Then type:

quit

Or just press Ctrl + D in some versions.

Practical Examples Of Telnet Usage

Telnet is most useful for manual protocol testing. Here are common scenarios where you might use it.

Testing SMTP Server

To check if an email server is responding on port 25:

telnet mail.example.com 25

Once connected, you can send a test email manually:

EHLO test.com
MAIL FROM: <user@test.com>
RCPT TO: <recipient@example.com>
DATA
Subject: Test
This is a test message.
.
QUIT

Checking HTTP Server

To see if a web server is running on port 80:

telnet example.com 80

Then send an HTTP GET request:

GET / HTTP/1.1
Host: example.com

Press Enter twice after the Host line. The server should return HTML content.

Testing POP3 Or IMAP

For email retrieval protocols:

telnet mail.example.com 110

Then log in with:

USER yourusername
PASS yourpassword
LIST
RETR 1
QUIT

Telnet Commands And Options

Telnet has several built-in commands accessible from the escape character (Ctrl + ]). Here are the most useful ones.

Command Description
close Close the current connection
open Connect to a host
quit Exit Telnet
set Set options like escape character
status Show current connection status
send Send special characters

Using The Escape Character

The default escape character is Ctrl + ]. You can change it with the -e option:

telnet -e ^A example.com

This sets the escape character to Ctrl + A.

Debug Mode

To see detailed connection information, use the -d flag:

telnet -d example.com 80

This shows socket operations and can help diagnose network issues.

Security Considerations When Using Telnet

Telnet sends all data unencrypted. This means anyone on your network can intercept passwords and commands. For production systems, always use SSH instead.

However, there are times when Telnet is acceptable:

  • On isolated lab networks
  • For testing purposes only
  • When connecting to legacy equipment that doesn’t support SSH
  • For quick port checks where no sensitive data is transmitted

If you must run a Telnet server, consider these precautions:

  1. Restrict access with firewall rules
  2. Use strong passwords
  3. Monitor logs for unauthorized access
  4. Disable Telnet when not needed

Telnet Vs SSH: Key Differences

SSH (Secure Shell) is the modern replacement for Telnet. Here’s how they compare.

Feature Telnet SSH
Encryption None Strong encryption
Authentication Plain text Public key or password
Port 23 22
Ease of use Very simple Simple
Security Low High
Protocol testing Excellent Limited

For everyday remote administration, SSH is the clear winner. But for manual protocol testing, Telnet’s raw text interface is often more convenient.

Troubleshooting Common Telnet Issues

Sometimes Telnet connections fail. Here are common problems and solutions.

Connection Refused

This means the remote host is not listening on the specified port. Check if the service is running:

sudo systemctl status apache2

Or verify firewall rules:

sudo ufw status

Connection Timed Out

A timeout indicates the host is unreachable. Check network connectivity:

ping example.com

If ping works but Telnet times out, a firewall might be blocking the port.

No Route To Host

This means the IP address is invalid or the network is down. Verify the hostname resolves correctly:

nslookup example.com

Telnet Command Not Found

If you get “command not found”, Telnet isn’t installed. Go back to the installation section above.

Using Telnet For Network Diagnostics

Telnet is a powerful tool for checking if services are reachable. Here’s a systematic approach.

Port Scanning With Telnet

You can test multiple ports manually:

telnet example.com 22
telnet example.com 80
telnet example.com 443

If you get a connection, the port is open. If you get “Connection refused”, it’s closed.

Testing Firewall Rules

Use Telnet from different network locations to verify firewall behavior. For example, test from inside and outside your network.

Checking Service Responsiveness

Once connected, you can see if the service responds quickly. Slow responses might indicate performance issues.

Automating Telnet Tasks With Scripts

While Telnet is interactive, you can automate simple tasks using input redirection or tools like expect.

Using Input Redirection

Create a text file with commands:

echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | telnet example.com 80

This sends an HTTP request and shows the response.

Using Expect For Automation

Expect is a scripting language for automating interactive programs. Install it first:

sudo apt install expect

Then create a script:

#!/usr/bin/expect
spawn telnet 192.168.1.100
expect "login:"
send "myusername\r"
expect "Password:"
send "mypassword\r"
expect "$ "
send "ls\r"
expect "$ "
send "exit\r"
interact

Telnet On Modern Linux Systems

Many Linux distributions now discourage Telnet use. Some don’t include it in default repositories. But you can still install it from legacy repositories or compile from source.

Using Netcat As An Alternative

Netcat (nc) can do many of the same things as Telnet:

nc -v example.com 80

Netcat is more flexible and often pre-installed. But Telnet’s interactive mode is easier for manual testing.

Telnet In Containers

If you use Docker or Podman, you can run Telnet inside a container:

docker run -it --rm alpine telnet example.com 80

This avoids installing Telnet on your host system.

Best Practices For Telnet Usage

To use Telnet safely and effectively, follow these guidelines.

  1. Only use Telnet on trusted networks
  2. Never log in with real credentials over Telnet
  3. Use Telnet for testing, not regular administration
  4. Disable Telnet services after testing
  5. Combine Telnet with other tools like tcpdump for deeper analysis
  6. Document what you test for future reference

Frequently Asked Questions

Is Telnet Still Used In Linux?

Yes, Telnet is still used for testing network services and accessing legacy equipment. Many system administrators keep it installed for quick port checks.

How Do I Enable Telnet In Linux?

Install the telnet package using your package manager. For the server, install telnetd and start the service with systemctl.

What Is The Difference Between Telnet And SSH?

Telnet sends data in plain text without encryption, while SSH encrypts all communication. SSH is secure for remote administration, while Telnet is mainly used for testing.

Can I Use Telnet To Test HTTPS On Port 443?

You can connect to port 443 with Telnet, but the session will be encrypted. You won’t see plain text HTTP traffic. Use OpenSSL instead: openssl s_client -connect example.com:443.

How Do I Exit Telnet If It Hangs?

Press Ctrl + ] to get the Telnet prompt, then type quit. If that doesn’t work, close the terminal or use kill command from another terminal.

Conclusion

Telnet in Linux remains a valuable tool for network diagnostics and protocol testing. While it’s not suitable for secure remote administration, its simplicity makes it perfect for quick checks.

You now know how to install Telnet, connect to remote hosts, test various services, and troubleshoot common issues. Remember to use Telnet only on trusted networks and switch to SSH for any sensitive operations.

Practice these commands on your own system. Try testing a local web server or checking if your email server is responding. With Telnet, you have a direct, text-based window into network services.