Telnet remains a reliable tool for remote server administration, even in modern Linux environments. If you are wondering how to use telnet linux for basic network troubleshooting or remote access, this guide will walk you through every step with clear, practical instructions.
Telnet is a network protocol that lets you connect to remote machines over a TCP/IP network. While SSH has largely replaced it for secure communications, telnet is still useful for testing ports, accessing legacy systems, or debugging services. In this article, you will learn installation, basic commands, and real-world usage examples.
What Is Telnet And Why Use It On Linux
Telnet stands for Teletype Network. It provides a bidirectional, text-based interface to remote hosts. The protocol operates on port 23 by default, but you can connect to any port for testing purposes.
Many administrators keep telnet installed for quick connectivity checks. For example, you can test if a web server is responding on port 80 without using a browser. Telnet is also handy for interacting with SMTP, HTTP, or other text-based protocols manually.
However, telnet sends all data, including passwords, in plain text. Never use it over untrusted networks. For secure remote shell access, always prefer SSH. But for local network diagnostics or controlled environments, telnet remains a lightweight option.
How To Install Telnet On Linux
Most modern Linux distributions do not include telnet by default. You need to install it manually. The package name varies slightly between distributions.
Install Telnet On Debian Or Ubuntu
Open a terminal and run the following command:
sudo apt update
sudo apt install telnet -y
This installs the telnet client. If you also need the server daemon, install telnetd:
sudo apt install telnetd -y
Install Telnet On Red Hat, CentOS, Or Fedora
For RPM-based systems, use:
sudo yum install telnet -y
Or on newer Fedora versions with dnf:
sudo dnf install telnet -y
To enable the telnet server, install telnet-server and start the service:
sudo yum install telnet-server -y
sudo systemctl start telnet.socket
sudo systemctl enable telnet.socket
Verify Installation
After installation, check that telnet is available:
telnet --version
You should see version information. If not, re-check your package manager commands.
How To Use Telnet Linux: Basic Commands
Now that telnet is installed, let us explore the core syntax. The basic command structure is:
telnet [hostname or IP address] [port]
If you omit the port, telnet defaults to port 23. Here are common usage examples:
- Connect to a remote server:
telnet 192.168.1.100 - Test a web server:
telnet example.com 80 - Check an email server:
telnet mail.example.com 25 - Connect to a custom port:
telnet 10.0.0.5 8080
Once connected, you can interact with the remote service. To exit a telnet session, press Ctrl+] to get the telnet prompt, then type quit and press Enter.
Telnet In Interactive Mode
When you run telnet without arguments, it enters interactive mode. You can then use commands like open, close, quit, or help.
telnet
telnet> open 192.168.1.100 23
telnet> close
telnet> quit
Interactive mode is useful for scripting or when you need to manage multiple connections.
Testing Network Services With Telnet
One of the most common reasons to learn how to use telnet linux is for troubleshooting network services. Telnet acts as a simple TCP client, letting you send raw text to any port.
Test HTTP Service On Port 80
To see if a web server is running, connect to port 80 and send an HTTP request:
telnet example.com 80
Trying 93.184.216.34...
Connected to example.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: example.com
Press Enter twice after the Host header. The server should respond with HTML content. If you see a connection refused error, the service is down or blocked.
Check SMTP Service On Port 25
For email servers, telnet helps verify if SMTP is listening:
telnet mail.example.com 25
220 mail.example.com ESMTP Postfix
EHLO test.com
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
You can send test emails manually, but that requires knowing SMTP commands. For basic checks, a successful connection and banner message indicate the service is up.
Verify SSH Port 22
Even though SSH is secure, you can test if port 22 is open using telnet:
telnet 192.168.1.100 22
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3
If you see an SSH version string, the service is responding. This is faster than using nmap for quick checks.
How To Use Telnet Linux For Remote Login
While not recommended for production, telnet can still provide remote shell access. This is useful on isolated networks or legacy systems.
Setting Up Telnet Server
First, ensure the telnet server is installed and running. On Ubuntu:
sudo apt install telnetd
sudo systemctl restart xinetd
On CentOS/RHEL:
sudo yum install telnet-server
sudo systemctl start telnet.socket
sudo systemctl enable telnet.socket
By default, telnet runs on port 23. You may need to configure firewall rules to allow incoming connections:
sudo ufw allow 23/tcp # Ubuntu
sudo firewall-cmd --add-port=23/tcp --permanent # CentOS
Connecting To A Telnet Server
From another machine, connect using:
telnet 192.168.1.100
You will be prompted for a username and password. Enter valid credentials. Once logged in, you get a shell prompt. Remember, all traffic is unencrypted.
Security Considerations
Never use telnet over the internet. Even on local networks, consider using SSH instead. If you must use telnet, restrict access with firewall rules and use strong passwords. Monitor logs for unauthorized access attempts.
Telnet Troubleshooting Common Errors
When using telnet, you may encounter errors. Here are solutions to frequent issues.
Connection Refused
This error means the remote host is not listening on the specified port. Possible causes:
- The service is not running.
- A firewall is blocking the port.
- The port number is incorrect.
Check the service status with systemctl status servicename. Verify firewall rules with sudo ufw status or sudo iptables -L.
Name Or Service Not Known
This indicates DNS resolution failure. Ensure the hostname is correct or use the IP address directly:
telnet 8.8.8.8 53
If using an IP address still fails, check your network connectivity.
Connection Timed Out
A timeout means the remote host is unreachable. This could be due to:
- Network congestion or routing issues.
- The remote host is down.
- A firewall is silently dropping packets.
Use ping to test basic connectivity. If ping works but telnet times out, a firewall is likely blocking the port.
Escape Character Not Working
Sometimes Ctrl+] does not respond. Try pressing Ctrl+5 or Ctrl+^ depending on your terminal. Alternatively, close the terminal window to end the session.
Telnet Alternatives And When To Use Them
While telnet is useful, modern tools offer better security and features. Here are common alternatives:
- SSH: Secure Shell encrypts all traffic. Use for remote login and command execution.
- Netcat (nc): A versatile networking tool for port scanning, file transfers, and debugging.
- Nmap: Advanced port scanning with service detection.
- Curl: Best for testing HTTP/HTTPS services with more control.
- PuTTY: A GUI client for Windows that supports telnet and SSH.
For most tasks, SSH is the recommended replacement. But telnet remains valuable for quick, lightweight tests where security is not a concern.
How To Use Telnet Linux In Scripts
Telnet can be automated using shell scripts. However, because telnet is interactive, you need to pipe commands or use expect.
Simple Script With Echo And Pipe
For basic connections, you can send commands via pipe:
echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | telnet example.com 80
This sends an HTTP request and prints the response. Note the \r\n for proper line endings.
Using Expect For Interactive Sessions
For login automation, install expect and write a script:
#!/usr/bin/expect
set timeout 20
spawn telnet 192.168.1.100
expect "login:"
send "myusername\r"
expect "Password:"
send "mypassword\r"
interact
Save the script, make it executable with chmod +x script.exp, and run it. Expect waits for specific prompts and sends responses.
Logging Telnet Output
To capture telnet output to a file, use the script command or redirect:
telnet example.com 80 | tee telnet_log.txt
This saves all output to a file while displaying it on screen.
Best Practices For Using Telnet
Follow these guidelines to use telnet safely and effectively:
- Only use telnet on trusted, isolated networks.
- Disable telnet server when not needed.
- Use strong passwords if you must enable login.
- Monitor logs for suspicious activity.
- Prefer SSH for any remote administration.
- Use telnet primarily for testing and debugging.
By following these practices, you minimize security risks while still leveraging telnet’s simplicity.
Frequently Asked Questions
How Do I Check If Telnet Is Installed On Linux?
Run telnet --version in the terminal. If it shows version info, telnet is installed. If you get “command not found”, install it using your package manager.
Can I Use Telnet To Test A Port Without Installing A Client?
Yes, you can use nc -zv host port (netcat) or timeout 1 bash -c "echo >/dev/tcp/host/port" as alternatives. But telnet is often simpler for interactive testing.
Is Telnet Secure For Remote Login?
No. Telnet sends all data, including passwords, in plain text. Use SSH instead for secure remote login. Telnet is only acceptable on isolated lab networks.
What Is The Default Port For Telnet?
The default port is 23. However, you can connect to any port by specifying it in the command, like telnet host 443 for HTTPS.
How Do I Exit A Telnet Session?
Press Ctrl+] to get the telnet prompt, then type quit and press Enter. Alternatively, close the terminal window.
Conclusion
Learning how to use telnet linux gives you a lightweight, effective tool for network troubleshooting and remote access. While it lacks security features, its simplicity makes it ideal for quick tests and legacy system management.
Remember to install telnet via your package manager, use the correct syntax for connections, and always prioritize SSH for sensitive tasks. With the steps in this guide, you can confidently use telnet for port testing, service verification, and basic remote login.
Practice these commands on your local network to build familiarity. Telnet may be old, but it remains a valuable skill in any Linux administrator’s toolkit.