在CentOS系统中,禁止Telnet访问可以通过以下几种方法实现:
安装firewalld(如果尚未安装):
sudo yum install firewalld
启动并启用firewalld服务:
sudo systemctl start firewalld
sudo systemctl enable firewalld
添加规则以阻止Telnet端口(默认端口23):
sudo firewall-cmd --permanent --remove-service=telnet
sudo firewall-cmd --reload
添加规则以阻止Telnet端口(默认端口23):
sudo iptables -A INPUT -p tcp --dport 23 -j DROP
保存iptables规则(CentOS 7及以上版本):
sudo systemctl stop firewalld
sudo systemctl disable firewalld
sudo yum install iptables-services
sudo systemctl start iptables
sudo systemctl enable iptables
sudo service iptables save
如果你主要使用SSH进行远程管理,可以禁用Telnet并加强SSH的安全性:
编辑SSH配置文件:
sudo vi /etc/ssh/sshd_config
找到并修改以下行:
#Port 22
Port 2222 # 更改SSH端口到一个非标准端口
禁用root登录:
PermitRootLogin no
重启SSH服务:
sudo systemctl restart sshd
如果你启用了SELinux,可以通过设置策略来进一步限制Telnet访问:
查看SELinux状态:
sestatus
编辑SELinux策略文件(例如/etc/selinux/config
):
sudo vi /etc/selinux/config
将SELinux设置为 enforcing 模式(如果尚未启用):
SELINUX=enforcing
重启系统以应用更改:
sudo reboot
通过以上方法,你可以有效地禁止Telnet访问,提高系统的安全性。