在 Linux 下使用 telnet 时报错,原因有很多种。下面按常见错误 → 原因 → 解决办法给你一个排查清单,你可以对照看是哪一种。
-bash: telnet: command not found
系统没有安装 telnet 客户端。
CentOS / RHEL
yum install -y telnet
Ubuntu / Debian
apt update
apt install -y telnet
Connection refused
netstat -lntp | grep 端口
# 或
ss -lntp | grep 端口
telnet 127.0.0.1 端口
iptables -L -n
# 或
firewall-cmd --list-all
Connected to x.x.x.x.
Escape character is '^]'.
(卡住)
或
Timed out
ping 目标IP
traceroute 目标IP
telnet 目标IP 端口
telnet: could not resolve hostname
telnet 192.168.1.10 23
cat /etc/resolv.conf
如果你是连自己 Linux 的 telnet 服务:
systemctl status telnet.socket
systemctl start telnet.socket
systemctl enable telnet.socket
⚠️ 建议:用 SSH 替代 telnet(明文传输不安全)
telnet 可以ssh user@ip
如果你能贴出具体的报错信息,我可以直接帮你定位是哪一类问题。