FTP IP 安全 <ipSecurity>

概述

<ipSecurity> 元素定义 FTP 7 中基于 IP 的安全限制的列表。 这些限制可以基于 IPv4 地址、IPv4 地址范围或 DNS 域名。

兼容性

版本 说明
IIS 10.0 <ipSecurity> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <ipSecurity> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <ipSecurity> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 <system.ftpServer/security> 元素的 <ipSecurity> 元素作为 IIS 7.5 的功能提供。
IIS 7.0 <system.ftpServer/security> 元素的 <ipSecurity> 元素是在 IIS 7.0 的独立下载项 FTP 7.0 中引入的。
IIS 6.0 空值

注意

FTP 7.0 和 FTP 7.5 服务是 IIS 7.0 带外提供的,需要从以下 URL 下载和安装模块:

https://www.iis.net/expand/FTP

在 Windows 7 和 Windows Server 2008 R2 中,FTP 7.5 服务作为 IIS 7.5 的功能提供,因此无需再下载 FTP 服务。

安装

若要支持 Web 服务器的 FTP 发布,必须安装 FTP 服务。 为此,请按照以下步骤操作。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在任务栏上,单击 “服务器管理器”。

  2. 在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。

  3. 在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。

  4. 在“服务器角色”页上,展开“Web 服务器 (IIS)”,然后选择“FTP 服务器”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS Manager 身份验证,除“FTP 服务”外还需选择“FTP 扩展性”
    Screenshot that shows F T P Service and F T P Extensibility selected for Windows Server 2012.

  5. 单击“下一步”,然后在“选择功能”页上,再次单击“下一步”。

  6. “确认安装选择”页上,单击“安装”

  7. 在“结果” 页面中单击“关闭”

Windows 8 或 Windows 8.1

  1. 在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”

  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。

  3. 展开“Internet Information Services”,然后选择“FTP 服务器”

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot that shows F T P Extensibility and F T P Service selected for Windows 8.

  4. 单击“确定”。

  5. 单击“关闭” 。

Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。

  2. 在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器 (IIS)”。

  3. 在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。

  4. 在“添加角色服务向导”的“选择角色服务”页,展开“FTP 服务器”。

  5. 选择“FTP 服务”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot that shows F T P Service and F T P Extensibility selected for Windows Server 2008.

  6. 单击 “下一步”

  7. “确认安装选择”页中,单击“安装”

  8. 在“结果” 页面中单击“关闭”

Windows 7

  1. 在任务栏上,单击“开始”,然后单击“控制面板”。

  2. 在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。

  3. 展开“Internet Information Services”,然后展开“FTP 服务器”

  4. 选择“FTP 服务”。

    注意

    若要支持 FTP 服务使用 ASP.Membership 身份验证或 IIS 管理器身份验证,还需选择“FTP 扩展性”
    Screenshot that shows F T P Extensibility and F T P Service selected for Windows 7.

  5. 单击“确定”。

Windows Server 2008 或 Windows Vista

  1. 从以下 URL 下载安装包:

  2. 按照以下演练中的说明安装 FTP 服务:

操作方式

如何添加 IP 限制以允许或访问 FTP 站点

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS) 管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services(IIS) 管理器”
    • 如果使用 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
  2. 在“连接”窗格中,展开服务器名称,展开“站点”,然后展开要为其添加 IP 限制的 FTP 站点或 URL。

  3. 在“主页”窗格中,双击“FTP IPv4 地址和域限制”功能。
    Screenshot that shows the contoso dot com Home pane, with F T P I P v 4 Address and Domain Restrictions selected.

  4. 在“FTP IPv4 地址和域限制”功能中的“操作”窗格中,单击“添加允许条目...”或“添加拒绝条目...”。
    Screenshot that shows the F T P I P v 4 Address and Domain Restrictions pane in the I I S Manager.

  5. 输入要允许或拒绝的 IP 地址,然后单击“确定”。
    Screenshot that shows the Add Deny Restriction Rule dialog box.


如何编辑 FTP 站点的 IP 限制功能设置

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS) 管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services(IIS) 管理器”
    • 如果使用 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet Information Services (IIS) 管理器”。
  2. 在“连接”窗格中,展开服务器名称,展开“站点”,然后展开要为其配置 IP 限制的 FTP 站点或 URL。

  3. 在“主页”窗格中,双击“FTP IPv4 地址和域限制”功能。
    Screenshot that shows the contoso dot com Home pane. F T P I P v 4 Address and Domain Restrictions is selected.

  4. 在“FTP IPv4 地址和域限制”功能中的“操作”窗格中,单击“编辑功能设置...”。
    Screenshot that shows the F T P I P v 4 Address and Domain Restrictions pane.

  5. 为未指定的客户端选择默认访问行为,指定是否按域名启用限制,然后单击“确定”。
    Screenshot that shows the Edit I P and Domain Restrictions Settings dialog box. Allow is selected.

配置

<ipSecurity> 元素在站点或 URL 级别配置。

规则按列表中显示的顺序从上到下进行处理。 最后处理 allowunlisted 属性。 关于 Internet 协议安全性 (IPsec) 限制,最佳做法是先列出拒绝规则。 如果此属性设置为 false,则无法清除 allowunlisted 属性。

特性

属性 说明
allowUnlisted 可选的 Boolean 属性。

指定是否允许未列出的 IP 地址。 将 allowUnlisted 属性设置为 true 将允许未列出的 IP 地址访问服务器。 将 allowUnlisted 属性设置为 false 将锁定服务器,防止访问所有 IP 地址,列出的 IP 地址除外。 如果要将此属性设置为 false,并且不将本地环回地址 (127.0.0.1) 列为允许的 IP 地址,则无法使用本地控制台中的浏览器访问服务器。

默认值为 true
enableReverseDns 可选的 Boolean 属性。

指定为 FTP 服务器启用或禁用反向域名系统 (DNS) 查找。 反向查找涉及在已知 IP 地址时查找域名。

警告:反向 DNS 查找将使用大量资源和时间。

默认值为 false

子元素

元素 说明
add 可选元素。

将 IP 限制添加到 IP 地址限制的集合中。
remove 可选元素。

<ipSecurity> 集合中移除对限制的引用。
clear 可选元素。

<ipSecurity> 集合中移除对限制的所有引用。

配置示例

以下示例演示 FTP 站点的 <system.ftpServer> 元素中的多个安全相关配置设置。 更具体而言,此示例中的 <location> 设置演示如何:

  • 为管理员组指定读取和写入访问权限的 FTP 授权规则。
  • 指定拒绝 *.exe、*.bat 和 *.cmd 文件的 FTP 请求筛选选项。
  • 指定最大内容长度为 1000000 字节且最大 URL 长度为 1024 字节的 FTP 请求限制。
  • 阻止 FTP 访问 _vti_bin 虚拟目录,此目录与 FrontPage 服务器扩展一起使用。
  • 指定 FTP IP 筛选选项,这些选项允许从 127.0.0.1 进行访问,但拒绝从 169.254.0.0/255.255.0.0 范围的 IP 地址进行访问。
<location path="ftp.example.com">
  <system.ftpServer>
    <security>
      <authorization>
        <add accessType="Allow" roles="administrators" permissions="Read, Write" />
      </authorization>
      <requestFiltering>
        <fileExtensions allowUnlisted="true">
          <add fileExtension=".exe" allowed="false" />
          <add fileExtension=".bat" allowed="false" />
          <add fileExtension=".cmd" allowed="false" />
        </fileExtensions>
        <requestLimits maxAllowedContentLength="1000000" maxUrl="1024" />
        <hiddenSegments>
          <add segment="_vti_bin" />
        </hiddenSegments>
      </requestFiltering>
      <ipSecurity enableReverseDns="false" allowUnlisted="true">
        <add ipAddress="127.0.0.1" allowed="true" />
        <add ipAddress="169.254.0.0" subnetMask="255.255.0.0" allowed="false" />
      </ipSecurity>
    </security>
  </system.ftpServer>
</location>

代码示例

以下示例将 FTP IP 安全性配置为允许未列出的 IP 地址,然后指定了如下 IP 限制:允许从 127.0.0.1 访问,但拒绝从 169.254.0.0/255.255.0.0 范围访问的 IP 地址进行访问。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.ftpServer/security/ipSecurity /allowUnlisted:"True" /commit:apphost

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

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

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 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.ftpServer/security/ipSecurity", "Default Web Site");
         ConfigurationElementCollection ipSecurityCollection = ipSecuritySection.GetCollection();

         ipSecuritySection["allowUnlisted"] = true;

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

         ConfigurationElement addElement1 = ipSecurityCollection.CreateElement("add");
         addElement1["ipAddress"] = @"169.254.0.0";
         addElement1["subnetMask"] = @"255.255.0.0";
         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.ftpServer/security/ipSecurity", "Default Web Site")
      Dim ipSecurityCollection As ConfigurationElementCollection = ipSecuritySection.GetCollection

      ipSecuritySection("allowUnlisted") = True

      Dim addElement As ConfigurationElement = ipSecurityCollection.CreateElement("add")
      addElement("ipAddress") = "127.0.0.1"
      addElement("allowed") = True
      ipSecurityCollection.Add(addElement)

      Dim addElement1 As ConfigurationElement = ipSecurityCollection.CreateElement("add")
      addElement1("ipAddress") = "169.254.0.0"
      addElement1("subnetMask") = "255.255.0.0"
      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.ftpServer/security/ipSecurity", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var ipSecurityCollection = ipSecuritySection.Collection;

ipSecuritySection.Properties.Item("allowUnlisted").Value = true;

var addElement = ipSecurityCollection.CreateNewElement("add");
addElement.Properties.Item("ipAddress").Value = "127.0.0.1";
addElement.Properties.Item("allowed").Value = true;
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";
ipSecurityCollection.AddElement(addElement1);

adminManager.CommitChanges();

VBScript

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

ipSecuritySection.Properties.Item("allowUnlisted").Value = True

Set addElement = ipSecurityCollection.CreateNewElement("add")
addElement.Properties.Item("ipAddress").Value = "127.0.0.1"
addElement.Properties.Item("allowed").Value = True
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"
ipSecurityCollection.AddElement(addElement1)

adminManager.CommitChanges()