Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

RedHat/CentOS 系統 Telnet 服務部署與安全加固完整指南

編輯:Linux 教學

⚠️ 重要安全警示

Telnet 為明文協議,帳號密碼網路傳輸完全可被竊聽。 生產環境**嚴禁**使用 Telnet 進行遠端管理,請改用 SSH (OpenSSH)。本文僅適用於:

  • 舊版嵌入式設備/網路設備相容測試。
  • 隔離實驗室環境教學演示。
  • 舊系統遷移臨時過渡。

環境:RedHat Enterprise Linux 7 / CentOS 7

步驟 1:安裝套件

# 檢查是否已安裝
rpm -q telnet telnet-server
# 未安裝則安裝 (通常需掛載安裝光碟或配置 yum 源)
yum install -y telnet telnet-server
# telnet-server 實際提供 xinetd 管理的 telnetd 服務

步驟 2:啟用服務 (由 xinetd 管理)

2.1 編輯配置檔

cp /etc/xinetd.d/telnet /etc/xinetd.d/telnet.bak
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          # yes → no
    # 可選:限制存取 IP
    # only_from       = 192.168.1.0/24
    # 可選:設定 banner
    # banner          = /etc/issue.net
}

2.2 重啟 xinetd

systemctl restart xinetd
systemctl enable xinetd   # 開機自啟

2.3 驗證監聽埠

ss -ntlp | grep :23
# 輸出應包含 LISTEN 0 128 *:23 *:* users:(("xinetd",pid=...,fd=...))

步驟 3:防火牆放行

# firewalld
firewall-cmd --permanent --add-port=23/tcp
firewall-cmd --reload
# 或 iptables
iptables -A INPUT -p tcp --dport 23 -j ACCEPT

步驟 4:SELinux (若為 Enforcing)

# 允許 telnetd 連線網路
setsebool -P telnetd_use_nfs on  # 若需掛載 NFS 家目錄
# 一般情況下預設政策允許,無需額外設定

步驟 5:客戶端測試

telnet 192.168.1.100
# 輸出應顯示登入提示
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is '^]'.
Red Hat Enterprise Linux Server release 7.x
Kernel 3.10.0-xxx.el7.x86_64 on an x86_64
login:

步驟 6:Root 登入限制 (預設禁止)

/etc/securetty 控制允許 root 登入的終端:

# 預設不包含 pts/*,故 root 無法 telnet 登入
# 如需開啟 (極不建議),編輯 /etc/securetty 新增
pts/0
pts/1
# ...
# 正確做法:一般用戶 telnet 登入後 su - root 或 sudo

安全加固清單 (若必須啟用)

措施實作
TCP Wrappers 限制 IP編輯 /etc/hosts.allow:in.telnetd: 192.168.1.0/255.255.255.0;/etc/hosts.deny:in.telnetd: ALL
xinetd only_from配置檔加入 only_from = 192.168.1.0/24
強制啟用強密碼策略/etc/security/pwquality.conf + pam_pwquality.so
登入失敗鎖定pam_faillock.so 配置
審計日誌確保 log_on_failure += USERID、log_on_success += PID HOST
定期更換密碼chage -M 90 等
替代方案:SSH立即部署 OpenSSH,停用 Telnet

常見故障排查

  • Connection refused:xinetd 未啟動、disable=yes、防火牆攔截、SELinux 拒絕。
  • No route to host:網路不通、防火牆 DROP。
  • Login incorrect:帳號密碼錯誤、/etc/passwd /etc/shadow 異常、PAM 配置錯誤、root 登入被 securetty 禁止。
  • 亂碼:終端編碼不匹配,設定 LANG=en_US.UTF-8 或終端編碼為 UTF-8。

結語

Telnet 部署極簡單,但**安全風險極高**。現代 Linux 運維鐵律:**預設拒絕 Telnet,全面推廣 SSH 金鑰認證、跳板機、VPN、零信任網路**。若因舊系統不得不暫時啟用,務必實施上述所有加固措施,並制定明確淘汰時間表。

Copyright © Windows教程網 All Rights Reserved