centos

CentOS防火墙如何阻止恶意IP访问

小樊
43
2025-09-05 17:34:50
栏目: 智能运维

在CentOS系统中,你可以使用firewalld或iptables来阻止恶意IP访问。以下是两种方法的详细步骤:

使用firewalld

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

    sudo yum install firewalld
    
  2. 启动firewalld服务

    sudo systemctl start firewalld
    
  3. 启用firewalld服务(使其在系统启动时自动运行):

    sudo systemctl enable firewalld
    
  4. 添加规则阻止恶意IP

    sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="恶意IP地址" reject'
    

    例如,要阻止IP地址为192.168.1.100的访问:

    sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject'
    
  5. 重新加载firewalld配置

    sudo firewall-cmd --reload
    

使用iptables

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

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

    sudo systemctl start iptables
    
  3. 启用iptables服务(使其在系统启动时自动运行):

    sudo systemctl enable iptables
    
  4. 添加规则阻止恶意IP

    sudo iptables -A INPUT -s 恶意IP地址 -j DROP
    

    例如,要阻止IP地址为192.168.1.100的访问:

    sudo iptables -A INPUT -s 192.168.1.100 -j DROP
    
  5. 保存iptables规则

    sudo service iptables save
    

注意事项

通过以上步骤,你可以有效地阻止恶意IP访问你的CentOS系统。

0
看了该问题的人还看了