在CentOS系统中,你可以使用firewalld
来禁止特定的IP地址。以下是具体步骤:
查看当前防火墙状态
sudo firewall-cmd --state
查看已加载的区域和规则
sudo firewall-cmd --list-all-zones
添加一个富规则(rich-rule)来拒绝特定IP
假设你想拒绝IP地址为192.168.1.100
的访问:
sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject'
重新加载防火墙配置
sudo firewall-cmd --reload
验证规则是否生效
sudo firewall-cmd --list-all-zones
如果你更喜欢使用iptables
,也可以通过以下步骤来禁止特定IP:
查看当前的iptables规则
sudo iptables -L -n
添加规则拒绝特定IP
假设你想拒绝IP地址为192.168.1.100
的访问:
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
保存iptables规则
CentOS 7及以上版本可以使用firewalld
来管理iptables规则,所以通常不需要手动保存。如果你使用的是CentOS 6或其他版本,可以使用以下命令保存规则:
sudo service iptables save
重启iptables服务
sudo service iptables restart
sudo
。通过以上步骤,你应该能够在CentOS系统中成功禁止特定IP地址的访问。