在 Debian 上 telnet 连接或登录速度慢,通常不是网络带宽问题,而是连接建立后等待响应慢或登录过程卡顿。常见原因和对应排查方法如下:
telnet 服务器(通常是 inetd + telnetd)在连接时会尝试 对客户端 IP 做反向 DNS 解析。
如果:
就会导致 登录前卡 5~30 秒
✅ 验证方法:
time telnet localhost
如果卡在:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
(卡在这里)
✅ 解决方法:
方法 1:telnetd 禁用 DNS 解析
# /etc/inetd.conf
telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetd -h
-h 表示不反向解析主机名
然后重启:
systemctl restart inetd
方法 2:客户端加 hosts
/etc/hosts
192.168.1.100 client
/etc/pam.d/login 或 /etc/pam.d/system-auth 中可能有:
pam_systemdpam_ldappam_ssspam_motd✅ 排查:
strace -f -o /tmp/telnet.log telnet localhost
✅ 临时测试:
# /etc/pam.d/login
# 注释掉 pam_motd.so
如果系统日志(journal)磁盘写入慢:
✅ 检查:
systemctl status systemd-logind
journalctl -p err -xb
⚠️ telnet 是 明文协议,Debian 官方已不推荐使用
✅ 替代方案:
ssh user@host
如果只是为了测试端口:
nc -vz host port
✅ 测试:
ping -M do -s 1472 host
mtr host
| 现象 | 原因 |
|---|---|
| 连接后卡几秒 | DNS 反向解析 |
| 登录慢 | PAM / motd |
| 偶尔慢 | 网络/防火墙 |
| 一直慢 | 服务配置错误 |
如果你愿意,可以贴出:
inetd 还是 systemd 启动 telnet我可以帮你精确判断。