在CentOS 8系统中,Telnet协议常用于远程管理设备和服务,尽管其安全性不如SSH,但在某些特定场景下仍具有实用价值,本文将详细介绍如何在CentOS 8上安装、配置和使用Telnet,并解答常见问题。

安装Telnet服务
确保系统已更新至最新状态,打开终端,执行以下命令:
sudo dnf update -y
安装Telnet服务器软件包,CentOS 8的默认软件源中包含telnet-server,可通过以下命令安装:
sudo dnf install telnet-server -y
安装完成后,启动Telnet服务并设置开机自启:
sudo systemctl start telnet.socket sudo systemctl enable telnet.socket
配置防火墙规则
CentOS 8默认使用firewalld作为防火墙工具,需开放Telnet默认端口(23)以允许远程连接:

sudo firewall-cmd --permanent --add-service=telnet sudo firewall-cmd --reload
若需指定端口开放,可使用:
sudo firewall-cmd --permanent --add-port=23/tcp
安全性增强建议
由于Telnet传输数据为明文,建议采取以下措施降低风险:
- 限制访问IP:通过防火墙规则仅允许特定IP连接。
- 临时关闭:非必要时停止服务:
sudo systemctl stop telnet.socket
- 替代协议:优先使用SSH(
sudo dnf install openssh-server)。
常见问题排查
若无法连接,检查以下事项:
- 服务状态:确认
telnet.socket正在运行:sudo systemctl status telnet.socket
- 网络连通性:使用
telnet <IP> 23测试本地或远程连接。
相关问答FAQs
Q1: CentOS 8安装Telnet时报错“Unable to find a match”怎么办?
A1: 可能是软件源未启用Telnet相关仓库,执行sudo dnf --enablerepo=PowerTools install telnet-server切换至扩展源安装。

Q2: 如何禁止root用户通过Telnet登录?
A2: 编辑/etc/securetty文件,删除或注释掉包含pts/的行,限制root仅能通过物理终端或SSH登录。