您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

实例层级公共 IP(经典)概述Instance level public IP (Classic) overview

实例层级公共 IP (ILPIP) 是可直接分配至 VM 或云服务角色实例(而非 VM 或角色实例所在的云服务)的公共 IP 地址。An instance level public IP (ILPIP) is a public IP address that you can assign directly to a VM or Cloud Services role instance, rather than to the cloud service that your VM or role instance reside in. ILPIP 不会取代分配给云服务的虚拟 IP (VIP)。An ILPIP doesn’t take the place of the virtual IP (VIP) that is assigned to your cloud service. 而是可以用来直接连接到 VM 或角色实例的其他 IP 地址。Rather, it’s an additional IP address that you can use to connect directly to your VM or role instance.

重要

Azure 具有用于创建和处理资源的两个不同的部署模型:Resource Manager 和经典Azure has two different deployment models for creating and working with resources: Resource Manager and classic. 本文介绍使用经典部署模型。This article covers using the classic deployment model. Microsoft 建议通过 Resource Manager 创建 VM。Microsoft recommends creating VMs through Resource Manager. 请确保你了解 IP 地址在 Azure 中的工作原理。Make sure you understand how IP addresses work in Azure.

ILPIP 和 VIP 之间的差异

如图 1 所示,云服务是使用 VIP 访问的,而各个 VM 通常是使用 VIP:<端口号>访问的。As shown in Figure 1, the cloud service is accessed using a VIP, while the individual VMs are normally accessed using VIP:<port number>. 通过将 ILPIP 分配给特定 VM,可以直接使用该 IP 地址访问该 VM。By assigning an ILPIP to a specific VM, that VM can be accessed directly using that IP address.

在 Azure 中创建云服务时,系统会自动创建相应的 DNS A 记录,以便通过完全限定的域名 (FQDN) 而非实际 VIP 来访问服务。When you create a cloud service in Azure, corresponding DNS A records are created automatically to allow access to the service through a fully qualified domain name (FQDN), instead of using the actual VIP. 系统会针对 ILPIP 执行相同的进程,以便通过 FQDN 而非 ILPIP 来访问 VM 或角色实例。The same process happens for an ILPIP, allowing access to the VM or role instance by FQDN instead of the ILPIP. 例如,如果创建了名为 contosoadservice 的云服务,且通过两个实例配置了名为 contosoweb 的 Web 角色,则 Azure 会为实例注册以下 A 记录:For instance, if you create a cloud service named contosoadservice, and you configure a web role named contosoweb with two instances, Azure registers the following A records for the instances:

  • contosoweb_IN_0.contosoadservice.cloudapp.netcontosoweb_IN_0.contosoadservice.cloudapp.net
  • contosoweb_IN_1.contosoadservice.cloudapp.netcontosoweb_IN_1.contosoadservice.cloudapp.net

备注

只能为每个 VM 或角色实例分配一个 ILPIP。You can assign only one ILPIP for each VM or role instance. 每个订阅最多可使用 5 个 ILPIP。You can use up to 5 ILPIPs per subscription. 多 NIC VM 不支持 LIPID。ILPIPs are not supported for multi-NIC VMs.

为什么要请求 ILPIP?Why would I request an ILPIP?

如果想要能够通过直接向其分配的 IP 地址链接到 VM 或角色实例,请为 VM 或角色实例请求 ILPIP,而不是使用云服务VIP:<端口号>。If you want to be able to connect to your VM or role instance by an IP address assigned directly to it, rather than using the cloud service VIP:<port number>, request an ILPIP for your VM or your role instance.

  • 主动 FTP - 通过向 VM 分配 ILPIP,可在任何端口上接收流量。Active FTP - By assigning an ILPIP to a VM, it can receive traffic on any port. VM 不需要终结点来接收流量。Endpoints are not required for the VM to receive traffic. 请参阅 FTP 协议概述 了解有关 FTP 协议的详细信息。See FTP Protocol Overview for details on the FTP protocol.
  • 出站 IP - 源自 VM 的出站流量会映射到充当源的 ILPIP,而 ILPIP 唯一标识针对外部实体的 VM。Outbound IP - Outbound traffic originating from the VM is mapped to the ILPIP as the source and the ILPIP uniquely identifies the VM to external entities.

备注

ILPIP 地址以前被称为公共 IP (PIP) 地址。In the past, an ILPIP address was referred to as a public IP (PIP) address.

管理 VM 的 ILPIPManage an ILPIP for a VM

在以下任务中,可通过 VM 创建、分配和删除 ILPIP:The following tasks enable you to create, assign, and remove ILPIPs from VMs:

在 VM 创建期间如何使用 PowerShell 请求 ILPIPHow to request an ILPIP during VM creation using PowerShell

下面的 PowerShell 脚本将创建名为 FTPService 的云服务,然后从 Azure 中检索映像,并使用检索到的映像创建名为 FTPInstance 的 VM,接着将 VM 设置为使用 ILPIP,最后再将 VM 添加到新服务:The following PowerShell script creates a cloud service named FTPService, retrieves an image from Azure, creates a VM named FTPInstance using the retrieved image, sets the VM to use an ILPIP, and adds the VM to the new service:

New-AzureService -ServiceName FTPService -Location "Central US"

$image = Get-AzureVMImage|?{$_.ImageName -like "*RightImage-Windows-2012R2-x64*"}

#Set "current" storage account for the subscription. It will be used as the location of new VM disk

Set-AzureSubscription -SubscriptionName <SubName> -CurrentStorageAccountName <StorageAccountName>

#Create a new VM configuration object

New-AzureVMConfig -Name FTPInstance -InstanceSize Small -ImageName $image.ImageName `
| Add-AzureProvisioningConfig -Windows -AdminUsername adminuser -Password MyP@ssw0rd!! `
| Set-AzurePublicIP -PublicIPName ftpip | New-AzureVM -ServiceName FTPService -Location "Central US"

如果要将另一个存储帐户指定为新 VM 磁盘的位置,可使用 MediaLocation 参数:If you want to specify another storage account as the location of new VM disk, you can use MediaLocation parameter:

    New-AzureVMConfig -Name FTPInstance -InstanceSize Small -ImageName $image.ImageName `
     -MediaLocation https://management.core.windows.net/<SubscriptionID>/services/storageservices/<StorageAccountName> `
    | Add-AzureProvisioningConfig -Windows -AdminUsername adminuser -Password MyP@ssw0rd!! `
    | Set-AzurePublicIP -PublicIPName ftpip | New-AzureVM -ServiceName FTPService -Location "Central US"

如何检索 VM 的 ILPIP 信息How to retrieve ILPIP information for a VM

要查看使用以上脚本创建的 VM 的 ILPIP 信息,请运行以下 PowerShell 命令,并观察 PublicIPAddressPublicIPName 的值:To view the ILPIP information for the VM created with the previous script, run the following PowerShell command and observe the values for PublicIPAddress and PublicIPName:

Get-AzureVM -Name FTPInstance -ServiceName FTPService

预期输出:Expected output:

DeploymentName              : FTPService
Name                        : FTPInstance
Label                       : 
VM                          : Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVM
InstanceStatus              : ReadyRole
IpAddress                   : 100.74.118.91
InstanceStateDetails        : 
PowerState                  : Started
InstanceErrorCode           : 
InstanceFaultDomain         : 0
InstanceName                : FTPInstance
InstanceUpgradeDomain       : 0
InstanceSize                : Small
HostName                    : FTPInstance
AvailabilitySetName         : 
DNSName                     : http://ftpservice888.cloudapp.net/
Status                      : ReadyRole
GuestAgentStatus            :   Microsoft.WindowsAzure.Commands.ServiceManagement.Model.GuestAgentStatus
ResourceExtensionStatusList : {Microsoft.Compute.BGInfo}
PublicIPAddress             : 104.43.142.188
PublicIPName                : ftpip
NetworkInterfaces           : {}
ServiceName                 : FTPService
OperationDescription        : Get-AzureVM
OperationId                 : 568d88d2be7c98f4bbb875e4d823718e
OperationStatus             : OK

如何删除 VM 的 ILPIPHow to remove an ILPIP from a VM

若要删除在以上脚本中添加到 VM 的 ILPIP,请运行以下 PowerShell 命令:To remove the ILPIP added to the VM in the previous script, run the following PowerShell command:

Get-AzureVM -ServiceName FTPService -Name FTPInstance | Remove-AzurePublicIP | Update-AzureVM

如何向现有 VM 添加 ILPIPHow to add an ILPIP to an existing VM

若要向使用以上脚本创建的 VM 添加 ILPIP,请运行以下命令:To add an ILPIP to the VM created using the script previous, run the following command:

Get-AzureVM -ServiceName FTPService -Name FTPInstance | Set-AzurePublicIP -PublicIPName ftpip2 | Update-AzureVM

管理云服务角色实例的 ILPIPManage an ILPIP for a Cloud Services role instance

要将 ILPIP 添加到云服务角色实例,请完成以下步骤:To add an ILPIP to a Cloud Services role instance, complete the following steps:

  1. 通过完成如何配置云服务文章中的步骤,下载云服务的 .cscfg 文件。Download the .cscfg file for the cloud service by completing the steps in the How to Configure Cloud Services article.
  2. 通过添加 InstanceAddress 元素更新 .cscfg 文件。Update the .cscfg file by adding the InstanceAddress element. 以下示例将名为 MyPublicIP 的 ILPIP 添加到名为 WebRole1 的角色实例中:The following sample adds an ILPIP named MyPublicIP to a role instance named WebRole1:

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceConfiguration serviceName="ILPIPSample" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-01.2.3">
      <Role name="WebRole1">
        <Instances count="1" />
          <ConfigurationSettings>
        <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
          </ConfigurationSettings>
      </Role>
      <NetworkConfiguration>
        <AddressAssignments>
          <InstanceAddress roleName="WebRole1">
        <PublicIPs>
          <PublicIP name="MyPublicIP" domainNameLabel="MyPublicIP" />
            </PublicIPs>
          </InstanceAddress>
        </AddressAssignments>
      </NetworkConfiguration>
    </ServiceConfiguration>
    
  3. 通过完成如何配置云服务文章中的步骤,上传云服务的 .cscfg 文件。Upload the .cscfg file for the cloud service by completing the steps in the How to Configure Cloud Services article.

如何检索云服务的 ILPIP 信息How to retrieve ILPIP information for a Cloud Service

若要查看每个角色实例的 ILPIP 信息,请运行以下 PowerShell 命令,并观察 PublicIPAddressPublicIPName 的值:To view the ILPIP information per role instance, run the following PowerShell command and observe the values for PublicIPAddress and PublicIPName:

$roles = Get-AzureRole -ServiceName PaaSFTPService -Slot Production -RoleName WorkerRole1 -InstanceDetails

$roles[0].PublicIPAddress
$roles[1].PublicIPAddress

后续步骤Next steps