在Windows IIS系统中,可以通过配置 web.config
文件来屏蔽特定IP地址或IP段的访问。web.config
文件是一个XML格式的配置文件,用于定义网站的行为和设置。以下是如何配置 web.config
文件以屏蔽特定IP地址或IP段的详细步骤。
步骤说明
- 创建或编辑
web.config
文件:如果网站根目录下没有web.config
文件,可以创建一个新的;如果已经存在,则直接编辑该文件。 - 配置
ipSecurity
元素:在web.config
文件中添加或修改<ipSecurity>
元素,设置allowUnlisted="true"
表示允许未列出的IP访问,然后使用<add>
元素指定需要屏蔽的IP地址或IP段。 - 保存并上传:保存修改后的
web.config
文件,并上传到网站的根目录,配置立即生效。<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <security> <ipSecurity allowUnlisted="true"> <clear/> <!-- 清除所有之前的IP规则 --> <add ipAddress="127.0.0.1"/> <!-- 允许单个IP地址访问 --> <add ipAddress="127.255.255.0" subnetMask="255.255.255.0"/> <!-- 屏蔽整个IP段 --> <add ipAddress="192.168.1.0" subnetMask="255.255.255.0"/> <!-- 屏蔽另一个IP段 --> </ipSecurity> </security> </system.webServer> </configuration>