centos

centos telnet防火墙设置

小樊
45
2025-10-17 09:27:14
栏目: 智能运维

CentOS系统Telnet防火墙配置步骤

1. 安装Telnet服务器

在配置防火墙前,需先确保Telnet服务已安装。CentOS系统默认未安装Telnet服务器,需通过以下命令安装:

sudo yum install telnet-server -y

2. 启动Telnet服务并设置开机自启

安装完成后,启动Telnet服务并配置为开机自动运行:

# 启动Telnet服务(CentOS 7及以上使用systemctl)
sudo systemctl start telnet.socket
# 设置开机自启
sudo systemctl enable telnet.socket

3. 配置防火墙允许Telnet流量

CentOS 7及以上版本默认使用firewalld作为防火墙管理工具,需通过以下步骤开放Telnet默认端口(23/tcp):

# 添加23/tcp端口到防火墙永久规则(--permanent表示永久生效)
sudo firewall-cmd --permanent --add-port=23/tcp
# 重新加载防火墙配置使更改生效
sudo firewall-cmd --reload

4. (可选)限制特定IP访问Telnet

若需提升安全性,可配置防火墙仅允许特定IP地址访问Telnet服务。例如,允许IP为192.168.1.100的客户端访问:

# 添加富规则(rich rule),仅允许指定IP访问23端口
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="23" accept'
# 重新加载防火墙配置
sudo firewall-cmd --reload

5. (可选)配置SELinux(若启用)

若系统启用了SELinux(默认启用),需确保其策略允许Telnet连接。可通过以下命令临时禁用SELinux测试是否为SELinux导致的问题:

# 临时禁用SELinux(重启后失效)
sudo setenforce 0

若需永久禁用SELinux,需编辑配置文件:

# 将SELINUX=enforcing改为SELINUX=disabled
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 重启系统使更改生效
sudo reboot

6. 验证Telnet连接

配置完成后,通过以下命令从客户端测试Telnet连接:

telnet 服务器IP地址 23

若连接成功,说明防火墙配置正确。

注意事项

0
看了该问题的人还看了