在Linux系统中,可以使用iptables或firewalld来配置IP黑名单。以下是两种方法的详细步骤:
查看当前iptables规则
sudo iptables -L -n -v
添加黑名单规则
假设要将IP地址192.168.1.100加入黑名单,阻止其所有流量:
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
sudo iptables -A OUTPUT -d 192.168.1.100 -j DROP
保存iptables规则 不同的Linux发行版保存iptables规则的方法不同:
sudo iptables-save > /etc/iptables/rules.v4
sudo service iptables save
或者sudo systemctl enable iptables
sudo systemctl start iptables
查看黑名单规则
sudo iptables -L -n -v | grep DROP
查看当前firewalld状态
sudo firewall-cmd --state
添加黑名单规则
假设要将IP地址192.168.1.100加入黑名单,阻止其所有流量:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" destination address="192.168.1.100" reject'
重新加载firewalld配置
sudo firewall-cmd --reload
查看黑名单规则
sudo firewall-cmd --list-all
通过以上步骤,你可以成功地在Linux系统中配置IP黑名单,从而阻止特定IP地址的访问。