在 Debian 上“限制 telnet”通常有以下几种含义和做法,你可以根据实际需求选择:
Telnet 是明文传输,极不安全,生产环境不建议使用。
sudo apt remove --purge telnetd inetd
sudo systemctl disable inetd
sudo ss -lntp | grep ':23'
无输出表示已关闭。
/etc/hosts.allow 和 /etc/hosts.deny假设使用 inetd + telnetd:
# 先拒绝所有
echo "telnetd: ALL" | sudo tee -a /etc/hosts.deny
# 允许指定 IP
echo "telnetd: 192.168.1.100" | sudo tee -a /etc/hosts.allow
✅ 效果:只允许 192.168.1.100 使用 telnet
只允许内网访问 23 端口:
sudo iptables -A INPUT -p tcp --dport 23 -s 192.168.1.0/24 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 23 -j DROP
查看规则:
sudo iptables -L -n
编辑:
sudo nano /etc/securetty
删除或注释:
tty1
tty2
...
或直接:
echo "pts/0" | sudo tee -a /etc/securetty
echo "user1" | sudo tee -a /etc/ftpusers
(/etc/ftpusers 也常用于 telnet 黑名单)
sudo ufw deny 23/tcp
| 需求 | 建议 |
|---|---|
| 安全 | 禁用 telnet,用 SSH |
| 必须保留 | 限制 IP + 禁止 root |
| 临时使用 | 防火墙限制来源 |
如果你能说明:必须保留 telnet 的原因 / Debian 版本,我可以给你更精确方案。