在CentOS系统中,你可以使用firewalld或iptables来阻止恶意IP访问。以下是两种方法的详细步骤:
安装firewalld(如果尚未安装):
sudo yum install firewalld
启动firewalld服务:
sudo systemctl start firewalld
启用firewalld服务(使其在系统启动时自动运行):
sudo systemctl enable firewalld
添加规则阻止恶意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'
重新加载firewalld配置:
sudo firewall-cmd --reload
安装iptables(如果尚未安装):
sudo yum install iptables-services
启动iptables服务:
sudo systemctl start iptables
启用iptables服务(使其在系统启动时自动运行):
sudo systemctl enable iptables
添加规则阻止恶意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
保存iptables规则:
sudo service iptables save
通过以上步骤,你可以有效地阻止恶意IP访问你的CentOS系统。