
Telnet Command in Linux/Unix – Quick Usage Guide
Telnet stands as one of the most fundamental networking tools in Unix and Linux systems, serving as a text-based protocol for establishing interactive connections to remote hosts. While it may seem antiquated in today’s security-conscious world, understanding telnet remains crucial for developers and system administrators who need to troubleshoot network services, test port connectivity, or work in isolated network environments. This guide will walk you through telnet’s core functionality, practical usage patterns, security considerations, and modern alternatives that have largely replaced it in production environments.
How Telnet Works Under the Hood
Telnet operates on the client-server model using TCP port 23 by default. The protocol establishes a virtual terminal connection between the client and server, transmitting all data including authentication credentials in plain text. When you initiate a telnet connection, the client sends character data to the server, which processes it and returns output back to the client’s terminal.
The protocol uses a simple command structure with special byte sequences called telnet commands, prefixed by the Interpret as Command (IAC) byte (255). These commands handle session negotiation, terminal type specification, and connection management.
Basic Telnet Commands and Syntax
The fundamental telnet command syntax follows this pattern:
telnet [hostname/ip] [port]
Here are the most commonly used telnet commands:
# Connect to a host on default port 23
telnet example.com
# Connect to specific port
telnet example.com 80
# Connect using IP address
telnet 192.168.1.100 22
# Exit telnet session
quit
# or
exit
# or press Ctrl+]
Interactive telnet commands while in a session:
# Enter telnet command mode
Ctrl+]
# Common telnet prompt commands
close # Close current connection
quit # Exit telnet
open # Open new connection
status # Display connection status
set # Set operating parameters
Step-by-Step Implementation Guide
Most Linux distributions include telnet by default, but if it’s missing, install it using your package manager:
# Ubuntu/Debian
sudo apt-get install telnet
# CentOS/RHEL/Fedora
sudo yum install telnet
# or for newer versions
sudo dnf install telnet
# Arch Linux
sudo pacman -S inetutils
For testing network connectivity, follow these steps:
# Step 1: Test if a port is open
telnet google.com 80
# Step 2: If successful, you'll see:
# Trying 172.217.164.110...
# Connected to google.com.
# Escape character is '^]'.
# Step 3: Test HTTP request
GET / HTTP/1.1
Host: google.com
# Step 4: Exit gracefully
^]
quit
Real-World Use Cases and Examples
Despite security limitations, telnet serves several practical purposes in modern environments:
- Port Connectivity Testing: Verify if services are running and accepting connections
- Protocol Testing: Manually interact with services like SMTP, HTTP, or POP3
- Network Troubleshooting: Isolate connectivity issues between application and network layers
- Legacy System Management: Access older network equipment that only supports telnet
Here’s how to test various services:
# Test SMTP server
telnet mail.example.com 25
# Expected response: 220 mail.example.com ESMTP
# Test HTTP server
telnet web.example.com 80
GET /index.html HTTP/1.0
Host: web.example.com
# Test SSH availability
telnet server.example.com 22
# Expected: SSH-2.0-OpenSSH_7.4
# Test database connectivity
telnet db.example.com 3306
# MySQL will respond with version info
# Test custom application
telnet app.example.com 8080
Telnet vs Modern Alternatives Comparison
Feature | Telnet | SSH | Netcat | cURL |
---|---|---|---|---|
Encryption | None | Strong encryption | None (basic) | TLS/SSL support |
Authentication | Plain text | Multiple methods | None | Various methods |
Port Testing | Excellent | Limited | Excellent | HTTP/HTTPS only |
Protocol Support | Any TCP | SSH protocol | TCP/UDP | HTTP/HTTPS/FTP |
Scripting | Difficult | Good | Excellent | Excellent |
Cross-platform | Universal | Universal | Universal | Universal |
Advanced Telnet Usage and Scripting
While telnet isn’t ideal for automation, you can script basic interactions using expect or simple shell redirections:
# Using expect for automated telnet sessions
#!/usr/bin/expect
spawn telnet 192.168.1.1
expect "login:"
send "admin\r"
expect "Password:"
send "password123\r"
expect "#"
send "show version\r"
expect "#"
send "exit\r"
interact
For simple connectivity checking in scripts:
#!/bin/bash
# Simple port checker using telnet
check_port() {
local host=$1
local port=$2
timeout 5 telnet $host $port 2>/dev/null | grep -q "Connected"
if [ $? -eq 0 ]; then
echo "Port $port on $host is open"
return 0
else
echo "Port $port on $host is closed or filtered"
return 1
fi
}
# Usage
check_port google.com 80
check_port localhost 22
Security Considerations and Best Practices
Understanding telnet’s security limitations is crucial for responsible usage:
- Never use telnet for authentication over untrusted networks
- Limit to local testing or isolated network segments
- Use SSH instead for remote shell access
- Disable telnet services on production servers
- Monitor telnet usage in network logs
Modern alternatives for telnet’s common use cases:
# Instead of telnet for connectivity testing
nc -zv hostname port
nmap -p port hostname
# Instead of telnet for HTTP testing
curl -I http://hostname
wget --spider http://hostname
# Instead of telnet for shell access
ssh user@hostname
# For automated testing
ncat --send-only < test_data hostname port
Troubleshooting Common Telnet Issues
When telnet connections fail, systematic troubleshooting helps identify the root cause:
# Connection refused
telnet: connect to address 192.168.1.1: Connection refused
# Solution: Service isn't running or firewall blocking
# Connection timeout
telnet: connect to address 192.168.1.1: Connection timed out
# Solution: Check network connectivity, routing, firewalls
# Name resolution failure
telnet: could not resolve hostname: Name or service not known
# Solution: Check DNS settings, use IP address instead
# Permission denied
telnet: Unable to connect to remote host: Permission denied
# Solution: Check if telnet client is installed and accessible
Debug network issues systematically:
# Step 1: Test basic connectivity
ping hostname
# Step 2: Check if port is filtered
nmap -p port hostname
# Step 3: Verify local network configuration
netstat -rn
ip route show
# Step 4: Check firewall rules
iptables -L
ufw status
Performance Characteristics and Limitations
Telnet's performance characteristics make it suitable for specific scenarios:
- Low overhead: Minimal protocol complexity results in fast connections
- Real-time interaction: Character-by-character transmission enables immediate response
- Universal compatibility: Works across virtually all TCP/IP implementations
- Simple debugging: Plain text nature makes troubleshooting straightforward
However, limitations include:
- No compression: All data transmitted uncompressed
- No multiplexing: Single channel per connection
- Limited terminal handling: Basic VT100 emulation
- No file transfer: Requires additional protocols for file operations
Integration with Modern DevOps Workflows
In contemporary DevOps practices, telnet serves narrow but important roles:
# Health check scripts
#!/bin/bash
# Check if application port responds
if timeout 3 telnet localhost 8080 2>/dev/null | grep -q "Connected"; then
echo "Application healthy"
exit 0
else
echo "Application unhealthy"
exit 1
fi
# Container readiness probes
# In Dockerfile or docker-compose.yml
HEALTHCHECK --interval=30s --timeout=3s \
CMD timeout 2 telnet localhost 3000 || exit 1
For monitoring and alerting systems:
# Nagios check command
define command{
command_name check_telnet
command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$
}
# Zabbix telnet check
telnet.run[{HOST.IP},80,3]
Modern networking tools have largely superseded telnet for most use cases, but understanding its functionality remains valuable for network troubleshooting and legacy system management. The RFC 854 specification provides complete technical details for those requiring deeper protocol understanding.
For production environments, prioritize secure alternatives like SSH, but keep telnet in your troubleshooting toolkit for those moments when you need to quickly verify basic TCP connectivity or interact with simple network services. The key is knowing when and where to apply this foundational tool appropriately while maintaining security best practices.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.