centos

CentOS如何禁止Telnet访问

小樊
40
2025-09-17 15:31:05
栏目: 智能运维

在CentOS系统中,禁止Telnet访问可以通过以下几种方法实现:

方法一:使用防火墙(firewalld)

  1. 安装firewalld(如果尚未安装):

    sudo yum install firewalld
    
  2. 启动并启用firewalld服务

    sudo systemctl start firewalld
    sudo systemctl enable firewalld
    
  3. 添加规则以阻止Telnet端口(默认端口23)

    sudo firewall-cmd --permanent --remove-service=telnet
    sudo firewall-cmd --reload
    

方法二:使用iptables

  1. 添加规则以阻止Telnet端口(默认端口23)

    sudo iptables -A INPUT -p tcp --dport 23 -j DROP
    
  2. 保存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配置

如果你主要使用SSH进行远程管理,可以禁用Telnet并加强SSH的安全性:

  1. 编辑SSH配置文件

    sudo vi /etc/ssh/sshd_config
    
  2. 找到并修改以下行

    #Port 22
    Port 2222  # 更改SSH端口到一个非标准端口
    
  3. 禁用root登录

    PermitRootLogin no
    
  4. 重启SSH服务

    sudo systemctl restart sshd
    

方法四:使用SELinux

如果你启用了SELinux,可以通过设置策略来进一步限制Telnet访问:

  1. 查看SELinux状态

    sestatus
    
  2. 编辑SELinux策略文件(例如/etc/selinux/config):

    sudo vi /etc/selinux/config
    
  3. 将SELinux设置为 enforcing 模式(如果尚未启用):

    SELINUX=enforcing
    
  4. 重启系统以应用更改

    sudo reboot
    

通过以上方法,你可以有效地禁止Telnet访问,提高系统的安全性。

0
看了该问题的人还看了