Ubuntu 服务器 Telnet 不稳定的排查与优化
一、先快速定位不稳定类型
二、服务与端口可用性检查
systemctl status telnet.socketsudo systemctl start telnet.socket、sudo systemctl enable telnet.socketsystemctl status xinetdsudo systemctl start xinetd、sudo systemctl enable xinetdss -tulnp | grep :23 或 netstat -tulnp | grep :23,应看到 0.0.0.0:23 或 :::23 处于 LISTENsudo apt update && sudo apt install telnetd xinetd/etc/xinetd.d/telnet 中 disable = no 并重启 xinetdtelnet <服务器IP> 23telnet -w 60 <服务器IP> 23三、网络与防火墙排查
ping <服务器IP> 检查可达性nslookup/dig <域名> 检查 DNS 解析是否正确ip route/route 检查路由是否异常sudo ufw allow 23/tcpsudo firewall-cmd --add-port=23/tcp --permanent && sudo firewall-cmd --reloadsudo iptables -A INPUT -p tcp --dport 23 -j ACCEPTtop/htop/uptime 观察 CPU/内存/负载是否过高导致新连接被丢弃或响应超时四、服务配置与日志定位
cat /etc/passwd | grep <用户名>,确保是 /bin/bash 等可用 shell/etc/xinetd.d/telnet 示例:service telnet
{
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}
sudo systemctl restart xinetd/var/log/auth.log(Debian/Ubuntu)grep "telnet" /var/log/auth.logtelnet -w 60 <IP> 23 提高超时阈值,观察是否仍出现超时/断开五、稳定性优化与安全建议
sudo ufw allow from 192.168.1.0/24 to any port 23 proto tcp/etc/xinetd.d/telnet 中设置并发实例:instances = 30(按实际内存与负载调整)sudo apt install stunnel4/etc/stunnel/stunnel.conf:[telnet]
accept = 443
connect = 127.0.0.1:23
cert = /etc/stunnel/stunnel.pem
sudo openssl req -new -x509 -days 365 -nodes -out /etc/stunnel/stunnel.pem -keyout /etc/stunnel/stunnel.pemsudo systemctl start stunnel4 && sudo systemctl enable stunnel4rsyslog 记录认证日志:sudo systemctl restart rsyslog/var/log/auth.log 与登录失败情况