centos

centos telnet如何限制访问IP

小樊
35
2025-09-09 15:28:39
栏目: 智能运维

在CentOS系统中,您可以使用firewalldiptables来限制Telnet访问的IP。以下是两种方法的详细步骤:

使用firewalld

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

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

    sudo systemctl start firewalld
    sudo systemctl enable firewalld
    
  3. 添加规则以允许特定IP访问Telnet端口(默认是23)

    sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="允许的IP地址" port protocol="tcp" port="23" accept'
    

    例如,如果您想允许IP地址为192.168.1.100的设备访问Telnet,可以运行:

    sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="23" accept'
    
  4. 重新加载firewalld配置

    sudo firewall-cmd --reload
    
  5. 验证规则是否已添加

    sudo firewall-cmd --list-all
    

使用iptables

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

    sudo yum install iptables-services
    
  2. 启动并启用iptables服务

    sudo systemctl start iptables
    sudo systemctl enable iptables
    
  3. 添加规则以允许特定IP访问Telnet端口(默认是23)

    sudo iptables -A INPUT -p tcp --dport 23 -s 允许的IP地址 -j ACCEPT
    

    例如,如果您想允许IP地址为192.168.1.100的设备访问Telnet,可以运行:

    sudo iptables -A INPUT -p tcp --dport 23 -s 192.168.1.100 -j ACCEPT
    
  4. 保存iptables规则

    sudo service iptables save
    
  5. 验证规则是否已添加

    sudo iptables -L -n
    

通过以上步骤,您可以成功限制CentOS系统上的Telnet访问仅限于特定的IP地址。请根据您的实际需求调整IP地址和端口号。

0
看了该问题的人还看了