在 Linux 下使用 telnet 时,常见错误主要分为连接类错误、认证/服务类错误、配置/环境类错误。下面按场景总结最常见的问题及含义。
Connection refused原因:
127.0.0.1,而你连的是外网 IP示例:
telnet 192.168.1.10 8080
Trying 192.168.1.10...
telnet: connect to address 192.168.1.10: Connection refused
排查:
ss -lntp | grep 8080
netstat -lntp | grep 8080
Connection timed out原因:
示例:
telnet 10.0.0.5 23
Trying 10.0.0.5...
telnet: connect to address 10.0.0.5: Connection timed out
排查:
ping 10.0.0.5
tcpdump -nn host 10.0.0.5
iptables -L -n
No route to host原因:
telnet: connect to address 192.168.100.1: No route to host
Name or service not known原因:
telnet example.test 23
example.test: Name or service not known
排查:
cat /etc/resolv.conf
nslookup example.test
Unable to connect to remote host通用错误,通常伴随上述原因(refused / timeout)
Login failed / 登录后立即断开原因:
/etc/securetty 限制Permission denied原因:
/sbin/nologin)telnet: command not found原因:
解决:
# CentOS / RHEL
yum install -y telnet
# Ubuntu / Debian
apt install -y telnet
Escape character is '^]'这不是错误! 表示 telnet 已连接成功,等待输入。
systemctl status telnet.socket
iptables -A INPUT -p tcp --dport 23 -j ACCEPT
常见错误:
disable = yes 未改only_from 限制过严⚠️ telnet 是明文协议,生产环境不推荐使用
sshping 目标IP
telnet IP 端口
ss -lntp | grep 端口
iptables -L -n
systemctl status telnet.socket
如果你愿意,可以告诉我:
我可以帮你精准定位问题。