在CentOS系统中,你可以使用firewalld来配置IP黑名单。以下是具体步骤:
安装firewalld(如果尚未安装):
sudo yum install firewalld 启动并启用firewalld服务:
sudo systemctl start firewalld sudo systemctl enable firewalld 添加IP黑名单: 使用firewall-cmd命令添加富规则来阻止特定IP地址。
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject' 这里的192.168.1.100是你想要阻止的IP地址。你可以根据需要替换为你想要阻止的IP地址。
重新加载firewalld配置:
sudo firewall-cmd --reload 验证规则是否添加成功:
sudo firewall-cmd --list-all 如果你更喜欢使用iptables,可以按照以下步骤操作:
安装iptables(如果尚未安装):
sudo yum install iptables 启动并启用iptables服务:
sudo systemctl start iptables sudo systemctl enable iptables 添加IP黑名单: 使用iptables命令添加规则来阻止特定IP地址。
sudo iptables -A INPUT -s 192.168.1.100 -j DROP 这里的192.168.1.100是你想要阻止的IP地址。你可以根据需要替换为你想要阻止的IP地址。
保存iptables规则: CentOS 7及以上版本使用firewalld,但你可以手动保存iptables规则。
sudo service iptables save 验证规则是否添加成功:
sudo iptables -L -n --permanent选项可以使规则在系统重启后仍然有效。通过以上步骤,你可以在CentOS系统中成功配置IP黑名单。