注:根據(jù)需求修改(8.8.4.4|8.8.8.)ip范圍(PS:注意,這里我們屏蔽是這2組IP范圍)
Linux下 規(guī)則文件.htaccess(手工創(chuàng)建.htaccess文件到站點根目錄)
<IfModule mod_rewrite.c>
RewriteEngine On
#Block ip
RewriteCond %{http:X-Forwarded-For}&%{REMOTE_ADDR}&%{http:X-Real-IP} (8.8.4.4|8.8.8.) [NC]
RewriteRule (.*) - [F]
</IfModule>
windows2003下
先開啟rewrite,然后添加以下規(guī)則。
#Block ip
RewriteCond %{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP} (8.8.4.4|8.8.8.) [NC]
RewriteRule (.*) - [F]
windows2008下 規(guī)則文件web.config (手工創(chuàng)建web.config文件到站點根目錄)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="band ip" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="%{HTTP_X_FORWARDED_FOR}&%{REMOTE_ADDR}&%{HTTP_X_Real_IP}" pattern="(8.8.4.4|8.8.8.)" />
</conditions>
<action type="AbortRequest" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
java主機屏蔽IP或IP段
在tomcat管理-》編輯server.xml
找到 <Host></Host>
在節(jié)點中配置
<Valve className="org.apache.catalina.valves.RemoteAddrValve" deny="8.8.4.4|8.8.4.*"/>
屏蔽后重啟tomcat生效,訪問提示403