Opening a terminal session and typing “telnet” followed by a hostname and port number establishes a raw network connection for testing. If you’re wondering how to telnet in Linux, you’ve come to the right place. Telnet is a simple, text-based protocol that lets you connect to remote servers and devices over a network. While it’s not secure for sensitive data, it remains a handy tool for troubleshooting and quick tests.
In this guide, you’ll learn everything you need to get started with telnet on Linux. We’ll cover installation, basic commands, common use cases, and even some security tips. Let’s jump right in.
What Is Telnet And Why Use It?
Telnet stands for “teletype network.” It’s one of the oldest network protocols, dating back to the early days of the internet. It allows you to connect to a remote computer and control it as if you were sitting right in front of it.
Today, telnet is mostly used for testing network services. For example, you can check if a web server is running on port 80 or if an email server is accepting connections on port 25. It’s also useful for debugging and configuring network devices like routers and switches.
However, telnet sends all data in plain text, including passwords. That’s why it’s not recommended for everyday remote administration. For secure connections, you should use SSH instead. But for quick checks and diagnostics, telnet is still a valuable tool.
How To Telnet In Linux
Now, let’s get to the core of this guide. Here’s a step-by-step breakdown of how to telnet in Linux. We’ll cover installation, basic usage, and some practical examples.
Step 1: Check If Telnet Is Installed
Most Linux distributions don’t come with telnet pre-installed anymore. To check if it’s already on your system, open a terminal and type:
telnet
If you see a message like “command not found,” you’ll need to install it. If telnet opens with a prompt, you’re good to go.
Step 2: Install Telnet On Your Linux System
The installation process varies depending on your distribution. Here are the commands for the most common ones:
- Debian/Ubuntu:
sudo apt update && sudo apt install telnet -y - Red Hat/CentOS/Fedora:
sudo yum install telnet -y(orsudo dnf install telnet -yon newer versions) - Arch Linux:
sudo pacman -S inetutils - OpenSUSE:
sudo zypper install telnet
After installation, verify it by typing telnet again. You should see a telnet prompt.
Step 3: Basic Telnet Syntax
The basic syntax for using telnet is:
telnet [hostname or IP address] [port number]
For example, to connect to a web server on port 80, you’d type:
telnet example.com 80
If you don’t specify a port, telnet uses the default port 23. But most modern uses require a specific port.
Step 4: Connect To A Remote Host
Let’s try a real example. Suppose you want to test if a mail server is listening on port 25 (SMTP). Type:
telnet mail.example.com 25
If the connection is successful, you’ll see a message from the server. If it fails, you’ll get an error like “Connection refused” or “No route to host.”
Step 5: Send Commands Over The Connection
Once connected, you can send text commands directly. For instance, after connecting to an SMTP server, you can type:
EHLO test.com
This initiates a handshake. The server will respond with its capabilities. To exit, press Ctrl+] to get the telnet prompt, then type quit.
Step 6: Exit The Telnet Session
To close a telnet connection, press Ctrl+] to escape to the telnet command line. Then type quit and press Enter. Alternatively, you can just close the terminal window.
Common Use Cases For Telnet
Telnet is not just for fun. It has several practical applications in network administration and troubleshooting.
Testing Web Servers
You can use telnet to check if a web server is responding. Connect to port 80 and send a simple HTTP request:
GET / HTTP/1.1
Host: example.com
Press Enter twice
If the server is working, you’ll get an HTTP response with headers and content.
Checking Email Servers
Telnet is great for testing SMTP, POP3, or IMAP servers. For example, to test an SMTP server on port 25:
telnet smtp.example.com 25
Then type EHLO test to see the server’s capabilities.
Diagnosing Firewall Issues
If a service isn’t accessible, telnet can help you determine if the port is blocked. A successful connection means the port is open. A timeout or refusal suggests a firewall or service issue.
Configuring Network Devices
Many routers, switches, and firewalls still support telnet for configuration. While SSH is preferred, telnet is often available as a fallback.
Telnet Security Concerns
Telnet is inherently insecure. All data, including passwords, is sent in plain text. This makes it vulnerable to eavesdropping and man-in-the-middle attacks.
For this reason, you should never use telnet over the internet or untrusted networks. Always use SSH for remote administration. Reserve telnet for local network testing and debugging.
If you must use telnet, consider using it only on isolated networks or with VPN protection. Also, disable telnet services on production systems to reduce attack surface.
Alternatives To Telnet
While telnet is useful, there are better tools for most tasks. Here are some alternatives:
- SSH: Secure Shell for encrypted remote access. Use this for any real work.
- Netcat (nc): A versatile tool for testing ports and sending data. It’s like telnet but more powerful.
- Nmap: For port scanning and service discovery.
- Curl: For testing HTTP/HTTPS services.
- PuTTY: A graphical client for SSH and telnet on Windows, but also available for Linux.
Troubleshooting Common Telnet Issues
Sometimes telnet doesn’t work as expected. Here are common problems and solutions.
Connection Refused
This means the remote host is not listening on that port. Check if the service is running. For example, if you’re testing a web server, make sure Apache or Nginx is started.
Connection Timed Out
A timeout usually indicates a firewall blocking the port or the host being unreachable. Check your network connectivity and firewall rules.
Command Not Found
If you see “telnet: command not found,” you need to install the telnet client. Refer to the installation steps above.
Garbled Output
Sometimes telnet displays strange characters. This can happen if the remote service sends binary data. Try using a different tool like netcat.
Advanced Telnet Tips
Once you’re comfortable with basic telnet, you can explore some advanced features.
Using Telnet With Different Ports
You can connect to any TCP port. For example, to test a MySQL database on port 3306:
telnet db.example.com 3306
If the port is open, you’ll get a connection. If not, you’ll see an error.
Telnet Escape Character
The default escape character is Ctrl+]. This brings you to the telnet command line, where you can type commands like close, quit, or status.
Telnet In Scripts
You can use telnet in shell scripts for automated testing. For example, you can pipe commands to telnet:
echo "GET / HTTP/1.1\nHost: example.com\n\n" | telnet example.com 80
This sends an HTTP request and displays the response.
Frequently Asked Questions
Q: Is telnet safe to use?
A: No, telnet is not secure. It sends data in plain text. Use SSH for secure connections.
Q: Can I telnet to any port?
A: Yes, you can connect to any TCP port. Just specify the port number after the hostname.
Q: What’s the difference between telnet and SSH?
A: Telnet is unencrypted, while SSH encrypts all traffic. SSH is the standard for remote administration.
Q: How do I install telnet on Ubuntu?
A: Run sudo apt install telnet -y in the terminal.
Q: Why does telnet say “Connection refused”?
A: The remote service is not running or the port is closed. Check the service status.
Final Thoughts
Telnet might be old, but it’s still a useful tool for quick network tests. Now you know how to telnet in Linux, from installation to advanced usage. Just remember to use it responsibly and avoid exposing sensitive data.
Practice with different ports and services. You’ll soon find telnet invaluable for diagnosing network issues. And if you need a secure alternative, SSH is always there.
Happy testing, and may your connections always be open!