在 Debian 上调试 telnet 问题,通常分为 服务是否启动、网络是否可达、配置是否正确、以及客户端行为 几个方面。下面按常见场景给你一套系统化的调试方法。
sudo apt update
sudo apt install telnetd inetd
Debian 通常使用 inetd 或 systemd socket 来启动 telnet。
sudo systemctl status inetd
# 或
sudo systemctl status telnet.socket
如果未运行:
sudo systemctl start inetd
sudo systemctl enable inetd
ss -lntp | grep 23
# 或
netstat -lntp | grep 23
正常应看到类似:
LISTEN 0 128 0.0.0.0:23
检查 /etc/inetd.conf:
grep telnet /etc/inetd.conf
应有类似:
telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetd
修改后重启:
sudo systemctl restart inetd
在服务器本机执行:
telnet localhost
# 或
telnet 127.0.0.1
✅ 成功示例:
Trying 127.0.0.1...
Connected to 127.0.0.1.
❌ 常见失败:
Connection refused → 服务未启动No route to host → 网络问题sudo iptables -L -n
临时放行测试:
sudo iptables -I INPUT -p tcp --dport 23 -j ACCEPT
sudo nft list ruleset
sudo apt install telnet
telnet -d 服务器IP
nc -vz 服务器IP 23
journalctl -u inetd -f
# 或
tail -f /var/log/syslog
/etc/passwd 用户是否可用/etc/shells/etc/securetty(某些系统限制 root telnet)| 错误 | 原因 | 解决 |
|---|---|---|
| Connection refused | telnet 未启动 | 启动 inetd |
| No route to host | 网络/防火墙 | 检查路由、iptables |
| 登录后立即断开 | shell 不可用 | 检查 /etc/shells |
| 卡在 Trying | 防火墙丢弃 | 放行 23 |
| 无响应 | inetd 配置错误 | 检查 inetd.conf |
⚠️ telnet 是明文协议,不建议在生产环境使用
推荐替代方案:
ssh user@server
如果只是为了调试端口连通性,可用:
nc -vz 服务器IP 端口
如果你愿意,可以告诉我:
cat /etc/debian_version)我可以帮你精确定位问题。