安全警示: Telnet 明文傳輸帳號密碼,生產環境嚴禁使用,請改用 SSH。本文僅供內網隔離環境、教學實驗或老舊設備維護參考。
yum install telnet-server -y
# CentOS 7 套件名相同
vim /etc/xinetd.d/telnet
# 修改 disable = no
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no
}
# 檢查 /etc/securetty 是否包含 pts/0 等
grep pts /etc/securetty
# 若無,手動添加
echo -e "pts/0\npts/1\npts/2\npts/3" >> /etc/securetty
再次警示: 開啟 root Telnet 登入極度危險,僅限極受控環境臨時使用。
# CentOS 6
service xinetd start
chkconfig xinetd on
# CentOS 7
systemctl start xinetd
systemctl enable xinetd
netstat -lnt | grep :23
# tcp 0 0 :::23 :::* LISTEN
useradd telnetuser
passwd telnetuser
# 客戶端連線
telnet
# 輸入帳號密碼測試
| 措施 | 實施方式 |
|---|---|
| 限制來源 IP | iptables -A INPUT -p tcp --dport 23 -s 192.168.1.0/24 -j ACCEPT; iptables -A INPUT -p tcp --dport 23 -j DROP |
| TCP Wrappers | /etc/hosts.allow: in.telnetd: 192.168.1.0/255.255.255.0; /etc/hosts.deny: in.telnetd: ALL |
| 改用 SSH | |
| VPN/堡壘機 | 將 Telnet 埠僅在 VPN 內網暴露 |
# 安裝 OpenSSH Server
yum install openssh-server -y
systemctl start sshd
systemctl enable sshd
# 禁用 Telnet
systemctl stop xinetd
systemctl disable xinetd
yum remove telnet-server
任何場景下,請優先部署 SSH,僅在極特殊舊設備無 SSH 支持時,才在嚴格網路隔離下啟用 Telnet。
