防火墙规则:在服务器的防火墙设置中,可以添加规则来阻止特定IP地址。
bash# 以iptables为例,阻止IP地址192.168.1.100访问服务器 sudo iptables -A INPUT -s 192.168.1.100 -j DROP
Web服务器配置:在Web服务器(如Apache或Nginx)的配置文件中,可以设置访问控制列表(ACL)来禁止特定IP。
apache# Apache示例,阻止IP地址192.168.1.100 <Directory /var/www/html> Order Deny,Allow Deny from 192.168.1.100 </Directory>
白名单配置
防火墙规则:在防火墙设置中,可以添加规则只允许特定IP地址访问。
bash# 以iptables为例,只允许IP地址192.168.1.100访问服务器 sudo iptables -A INPUT -s 192.168.1.100 -j ACCEPT sudo iptables -A INPUT -j DROP # 拒绝所有其他IP
Web服务器配置:在Web服务器的配置文件中,可以设置只允许特定IP访问。
apache# Apache示例,只允许IP地址192.168.1.100 <Directory /var/www/html> Order Deny,Allow Deny from all Allow from 192.168.1.100 </Directory>