共用方式為


新增 IP 安全性 < 新增>

概觀

集合 <add><ipSecurity> 元素會定義唯一的 IP 安全性限制。 每個限制都可以以 IP 第 4 版位址、IP 第 4 版位址範圍或 DNS 功能變數名稱為基礎。

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <add>
IIS 8.5 未在 IIS 8.5 中修改專案 <add>
IIS 8.0 未在 IIS 8.0 中修改專案 <add>
IIS 7.5 未在 IIS 7.5 中修改專案 <add>
IIS 7.0 <add>集合的 <ipSecurity> 元素是在 IIS 7.0 中引進。
IIS 6.0 集合 <ipSecurity> 會取代 IIS 6.0 IPSecurity Metabase 屬性。

安裝程式

IIS 的預設安裝不包含 IP 安全性的角色服務或 Windows 功能。 若要在 IIS 上使用 IP 安全性,您必須使用下列步驟來安裝角色服務或 Windows 功能:

Windows Server 2012 或 Windows Server 2012 R2

  1. 在工作列上,按一下 [伺服器管理員]
  2. [伺服器管理員] 中,按一下 [管理] 功能表,然後按一下 [新增角色及功能]。
  3. 在 [ 新增角色及功能精 靈] 中,按 [ 下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
  4. 在 [ 伺服器角色] 頁面上,依序展開 [ Web 服務器] (IIS) 、[ Web 服務器]、[ 安全性],然後選取 [ IP 和網域限制]。 按一下 [下一步] 。
    此螢幕擷取畫面顯示針對 Windows Server 2012 選取的 I P 和網域限制。 .
  5. 在 [選取功能] 頁面上,按 [下一步]
  6. 在 [確認安裝選項] 頁面上,按一下 [安裝]
  7. 在 [結果] 頁面上,按一下 [關閉]

Windows 8 或 Windows 8.1

  1. 在 [開始] 畫面上,將指標一路移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
  3. 序展開 [Internet Information Services]、[ 萬維網服務]、[ 安全性],然後選取 [ IP 安全性]。
    顯示已針對 Windows 8 選取 [I P 安全性] 的螢幕擷取畫面。
  4. 按一下 [確定]。
  5. 按一下 [關閉] 。

Windows Server 2008 或 Windows Server 2008 R2

  1. 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。

  2. [伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS)

  3. 在 [ Web Server (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。

  4. 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取[IP 和網域限制],然後按 [下一步]。

    顯示針對 Windows Server 2008 選取 [I P] 和 [網域限制] 的螢幕擷取畫面。

  5. 在 [確認安裝選項] 頁面上,按一下 [安裝]

  6. 在 [結果] 頁面上,按一下 [關閉]

Windows Vista 或 Windows 7

  1. 在工作列上,按一下 [開始],然後按一下[主控台]。

  2. 主控台中,按一下 [程式和功能],然後按一下[開啟或關閉 Windows 功能]。

  3. 依序展開 [Internet Information Services]、[ World Wide Web 服務] 和 [ 安全性]。

  4. 選取 [IP 安全性],然後按一下 [ 確定]。

    顯示針對 Windows Vista 或 Windows 7 選取 [I P 安全性] 的螢幕擷取畫面。

作法

如何新增 IP 限制以拒絕網站存取

  1. 開啟 [Internet Information Services (IIS) 管理員

    • 如果您使用 Windows Server 2012 或 Windows Server 2012 R2:

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows 8 或 Windows 8.1:

      • 按住Windows鍵,按字母X,然後按一下[主控台]。
      • 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows Server 2008 或 Windows Server 2008 R2:

      • 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
    • 如果您使用 Windows Vista 或 Windows 7:

      • 在工作列上,按一下 [開始],然後按一下[主控台]。
      • 按兩下 [系統管理工具],然後按兩下 [ Internet Information Services] (IIS) Manager
  2. 在 [ 連線] 窗格中,展開伺服器名稱、 [網站],然後展開您要為其新增 IP 限制的網站、應用程式或 Web 服務。

  3. 在 [ 首頁 ] 窗格中,按兩下 [ IP 位址和網域限制] 功能。
    顯示 I I S Manager 中 [首頁] 窗格的螢幕擷取畫面。

  4. 在 [IP 位址和網域限制]功能中,按一下 [動作] 窗格中的 [新增拒絕專案...]。
    顯示 [I P 位址和網域限制] 窗格的螢幕擷取畫面。

  5. 輸入您想要拒絕的 IP 位址,然後按一下 [ 確定]。
    顯示 [新增拒絕限制規則] 對話方塊的螢幕擷取畫面。


如何編輯網站的 IP 限制功能設定

  1. 開啟 [Internet Information Services (IIS) 管理員

    • 如果您使用 Windows Server 2012 或 Windows Server 2012 R2:

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows 8 或 Windows 8.1:

      • 按住Windows鍵,按字母X,然後按一下[主控台]。
      • 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows Server 2008 或 Windows Server 2008 R2:

      • 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
    • 如果您使用 Windows Vista 或 Windows 7:

      • 在工作列上,按一下 [開始],然後按一下[主控台]。
      • 按兩下 [系統管理工具],然後按兩下 [ Internet Information Services] (IIS) Manager
  2. 在 [ 連線] 窗格中,展開伺服器名稱、 [網站],然後展開您要為其新增 IP 限制的網站、應用程式或 Web 服務。

  3. 在 [ 首頁 ] 窗格中,按兩下 [ IP 位址和網域限制] 功能。
    顯示 Internet Information Services Manager 中 [首頁] 窗格的螢幕擷取畫面。

  4. 在 [IP 位址和網域限制] 功能中,按一下 [動作] 窗格中的 [編輯功能設定...]。
    顯示 [I P 位址和網域限制] 視窗的螢幕擷取畫面。

  5. 為未指定的用戶端選擇預設存取行為、指定是否要依功能變數名稱啟用限制、指定是否啟用 Proxy 模式、選取 [拒絕動作類型],然後按一下 [ 確定]。
    顯示 [新增拒絕限制規則] 對話方塊的螢幕擷取畫面。[拒絕動作類型] 底下已選取 [禁止]。

組態

規則會依照規則出現在清單中的順序,從上到下進行處理。 allowunlisted 屬性最後處理。 網際網路通訊協定安全性 (IPsec) 限制的最佳做法是先列出拒絕規則。

屬性

屬性 描述
allowed 選擇性的 Boolean 屬性。

指定是否允許存取位址空間。

預設值是 false
domainName 選擇性字串屬性。

指定要對其強制執行限制規則的功能變數名稱。 您可以使用星號 (*) 作為萬用字元。
ipAddress 選擇性字串屬性。

指定要對其施加限制規則的 IP 第 4 版位址。
subnetMask 選擇性字串屬性。

指定要評估此限制規則 IP 位址的子網路遮罩。 您可以使用子網路遮罩來識別位址空間中的 IP 位址範圍。 預設值需要有效評估 IP 位址的直接比對 (,也就是單一位址的範圍) 。

預設值是 255.255.255.255

子元素

無。

組態範例

下列組態範例會將兩個 IP 限制新增至預設網站;第一個限制會拒絕存取 IP 位址 192.168.100.1,而第二個限制會拒絕存取整個 169.254.0.0 網路。

<location path="Default Web Site">
   <system.webServer>
      <security>
         <ipSecurity>
            <add ipAddress="192.168.100.1" />
            <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" />
         </ipSecurity>
      </security>
   </system.webServer>
</location>

範例程式碼

下列程式碼範例會將兩個 IP 限制新增至預設網站;第一個限制會拒絕存取 IP 位址 192.168.100.1,而第二個限制會拒絕存取整個 169.254.0.0 網路。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/security/ipSecurity /+"[ipAddress='192.168.100.1',allowed='False']" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.webServer/security/ipSecurity /+"[ipAddress='169.254.0.0',subnetMask='255.255.0.0',allowed='False']" /commit:apphost

注意

當您使用AppCmd.exe設定這些設定時,請務必將 認可 參數 apphost 設定為 。 這會將組態設定認可至ApplicationHost.config檔案中適當的位置區段。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", "Default Web Site");
         ConfigurationElementCollection ipSecurityCollection = ipSecuritySection.GetCollection();

         ConfigurationElement addElement = ipSecurityCollection.CreateElement("add");
         addElement["ipAddress"] = @"192.168.100.1";
         addElement["allowed"] = false;
         ipSecurityCollection.Add(addElement);

         ConfigurationElement addElement1 = ipSecurityCollection.CreateElement("add");
         addElement1["ipAddress"] = @"169.254.0.0";
         addElement1["subnetMask"] = @"255.255.0.0";
         addElement1["allowed"] = false;
         ipSecurityCollection.Add(addElement1);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim ipSecuritySection As ConfigurationSection = config.GetSection("system.webServer/security/ipSecurity", "Default Web Site")
      Dim ipSecurityCollection As ConfigurationElementCollection = ipSecuritySection.GetCollection

      Dim addElement As ConfigurationElement = ipSecurityCollection.CreateElement("add")
      addElement("ipAddress") = "192.168.100.1"
      addElement("allowed") = False
      ipSecurityCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = ipSecurityCollection.CreateElement("add")
      addElement1("ipAddress") = "169.254.0.0"
      addElement1("subnetMask") = "255.255.0.0"
      addElement1("allowed") = False
      ipSecurityCollection.Add(addElement1)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var ipSecuritySection = adminManager.GetAdminSection("system.webServer/security/ipSecurity", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var ipSecurityCollection = ipSecuritySection.Collection;

var addElement = ipSecurityCollection.CreateNewElement("add");
addElement.Properties.Item("ipAddress").Value = "192.168.100.1";
addElement.Properties.Item("allowed").Value = false;
ipSecurityCollection.AddElement(addElement);

var addElement1 = ipSecurityCollection.CreateNewElement("add");
addElement1.Properties.Item("ipAddress").Value = "169.254.0.0";
addElement1.Properties.Item("subnetMask").Value = "255.255.0.0";
addElement1.Properties.Item("allowed").Value = false;
ipSecurityCollection.AddElement(addElement1);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set ipSecuritySection = adminManager.GetAdminSection("system.webServer/security/ipSecurity", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set ipSecurityCollection = ipSecuritySection.Collection

Set addElement = ipSecurityCollection.CreateNewElement("add")
addElement.Properties.Item("ipAddress").Value = "192.168.100.1"
addElement.Properties.Item("allowed").Value = False
ipSecurityCollection.AddElement(addElement)

Set addElement1 = ipSecurityCollection.CreateNewElement("add")
addElement1.Properties.Item("ipAddress").Value = "169.254.0.0"
addElement1.Properties.Item("subnetMask").Value = "255.255.0.0"
addElement1.Properties.Item("allowed").Value = False
ipSecurityCollection.AddElement(addElement1)

adminManager.CommitChanges()