How to Fix “-bash: telnet: command not found” Error Despite Telnet Service Running


2 views

The error message "-bash: telnet: command not found" typically occurs when the telnet client package isn't installed on your system, even though the telnet server might be running through xinetd. This is a common point of confusion among Linux administrators.

The key distinction here is between:

1. telnet-server (what you've configured in xinetd)
2. telnet-client (the missing component causing your error)

For Debian/Ubuntu systems:

sudo apt-get update
sudo apt-get install telnet

For RHEL/CentOS systems:

sudo yum install telnet

After installation, verify with:

which telnet
# Expected output: /usr/bin/telnet

Try connecting to your local telnet server:

telnet localhost

Or test a remote connection (replace with actual IP):

telnet 192.168.1.100

If you still encounter issues, verify the service status:

sudo service xinetd status

Check firewall settings:

sudo iptables -L -n

While telnet is useful for testing, remember it transmits data in plaintext. For production environments, consider SSH instead:

ssh username@hostname

The error message "-bash: telnet: command not found" typically occurs when the telnet client package is not installed on your Linux system, even though the telnet server service might be running through xinetd. These are two separate components:

# Server component (what you have installed)
telnet-server package (handles incoming connections)

# Client component (what's missing)
telnet package (provides the telnet command)

From your service listing, we can see telnet is indeed enabled in xinetd:

xinetd based services:
        telnet:         on

But the client utility is missing. Let's verify this:

which telnet || echo "Telnet client not found"
rpm -q telnet || dpkg -l telnet | grep ^ii || echo "Package not installed"

The solution varies by Linux distribution:

For RHEL/CentOS/Fedora:

sudo yum install telnet
# Or for newer versions:
sudo dnf install telnet

For Debian/Ubuntu:

sudo apt-get update
sudo apt-get install telnet

For Arch Linux:

sudo pacman -S inetutils

After installation, verify it works:

telnet localhost
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

While we're fixing the immediate issue, consider these modern alternatives:

# Using netcat (nc) for basic connectivity testing:
nc -zv hostname port

# Using SSH for secure connections:
ssh user@hostname -p port

# Using curl for HTTP services:
curl -v telnet://hostname:port

If you still can't connect after installing telnet, check these:

# Verify service is listening:
netstat -tulnp | grep telnet
ss -tulnp | grep telnet

# Check firewall rules:
sudo iptables -L -n -v
sudo firewall-cmd --list-all

# Test basic connectivity:
ping hostname
traceroute hostname

Remember that telnet transmits data in plaintext. For production systems, consider:

# Disabling telnet in xinetd:
sudo sed -i 's/^.*telnet.*$/        telnet:         off/' /etc/xinetd.d/telnet
sudo systemctl restart xinetd

# Using SSH instead:
sudo apt-get install openssh-server   # Debian/Ubuntu
sudo yum install openssh-server       # RHEL/CentOS