使用 Azure 门户为虚拟机配置专用 IP 地址Configure private IP addresses for a virtual machine using the Azure portal

系统会从指定的范围自动为虚拟机 (VM) 分配专用 IP 地址,具体取决于部署时所在的子网。A virtual machine (VM) is automatically assigned a private IP address from a range that you specify, based on the subnet it is deployed in. 该地址会由某个 VM 保留,直到该 VM 被删除。The address is retained by a VM until the VM is deleted. Azure 从你创建 VM 时所在的子网动态分配下一个可用的专用 IP 地址。Azure dynamically assigns the next available private IP address from the subnet you create a VM in. 如果需要已分配给 VM 的子网中的特定 IP 地址,请分配静态 IP 地址。Assign a static IP address if you want a specific IP address from the subnet assigned to the VM.

Important

在使用 Azure 资源之前,请务必了解 Azure 当前具有的两种部署模型:Azure 资源管理器和经典。Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure Resource Manager and classic. 在使用任何 Azure 资源之前,请确保了解 部署模型和工具Make sure you understand deployment models and tools before you work with any Azure resource. 可以通过单击本文顶部的选项卡来查看不同工具的文档。You can view the documentation for different tools by clicking the tabs at the top of this article.

本文介绍 Resource Manager 部署模型。This article covers the Resource Manager deployment model. 还可以 管理经典部署模型中的静态专用 IP 地址You can also manage static private IP address in the classic deployment model.

方案Scenario

为了更好地说明如何为 VM 配置静态 IP 地址,本文档使用以下方案。To better illustrate how to configure a static IP address for a VM, this document will use the scenario below.

VNet 方案

在此方案中,将在 FrontEnd 子网中创建一个名为 DNS01 的 VM,并将它设置为使用静态 IP 地址 192.168.1.101In this scenario you will create a VM named DNS01 in the FrontEnd subnet, and set it to use a static IP address of 192.168.1.101.

需要已创建一个简单的环境才能执行以下示例步骤。The following sample steps expect a simple environment already created. 若要运行本文档中所显示的步骤,请先生成创建虚拟网络 中所述的测试环境。If you want to run the steps as they are displayed in this document, first build the test environment described in Create a virtual network.

如何创建用于测试静态专用 IP 地址的 VMHow to create a VM for testing static private IP addresses

在 Resource Manager 部署模型中创建 VM 时,不能使用 Azure 门户设置静态专用 IP 地址。You cannot set a static private IP address during the creation of a VM in the Resource Manager deployment mode by using the Azure portal. 必须先创建 VM,然后再将其专用 IP 设置为静态。You must create the VM first, then set its private IP to be static.

若要在名为 TestVNet 的 VNet 的前端子网中创建名为 DNS01 的 VM,请按以下步骤操作 :To create a VM named DNS01 in the FrontEnd subnet of a VNet named TestVNet, follow these steps:

  1. 在浏览器中导航到 https://portal.azure.cn,并在必要时使用 Azure 帐户登录。From a browser, navigate to https://portal.azure.cn and, if necessary, sign in with your Azure account.

  2. 单击“创建资源” > “计算” > “Windows Server 2012 R2 数据中心”,确认“选择部署模型”列表已显示“资源管理器”,然后单击“创建”,如下图所示 。Click Create a resource > Compute > Windows Server 2012 R2 Datacenter, notice that the Select a deployment model list already shows Resource Manager, and then click Create, as seen in the following figure.

    在 Azure 门户中创建 VM

  3. 在“基本信息”窗格中,输入要创建的 VM 的名称(在此方案中为DNS01)、本地管理员帐户和密码,如下图所示 。In the Basics pane, enter the name of the VM to create (DNS01 in the scenario), the local administrator account, and password, as seen in the following figure.

    “基本信息”窗格

  4. 请确保所选“位置”为“中国北部”,并在“资源组”下单击“选择现有项”,接着依次单击“资源组”、“TestRG”和“确定”。 Make sure the Location selected is China North, then click Select existing under Resource group, then click Resource group again, then click TestRG, and then click OK.

    “基本信息”窗格

  5. 在“选择大小”窗格中,选择“A1 标准”,然后单击“选择” 。In the Choose a size pane, select A1 Standard, and then click Select.

    选择“大小”窗格

  6. 在“设置”窗格中,确保属性设置为以下值,然后单击“确定” 。In the Settings pane, be sure the properties are set with the following values, and then click OK.

    -存储帐户vnetstorage-Storage account: vnetstorage

    • 网络TestVNetNetwork: TestVNet
    • 子网FrontEndSubnet: FrontEnd

    选择“大小”窗格

  7. 在“摘要”窗格中,单击“确定” 。In the Summary pane, click OK. 请注意,以下磁贴会显示在仪表板中。Notice the following tile displayed in your dashboard.

    在 Azure 门户中创建 VM

我们建议,除非有必要(例如,为一个 Windows VM 分配多个 IP 地址时),否则不要以静态方式在 VM 的操作系统中分配已分配给 Azure 虚拟机的专用 IP。It's recommended that you do not statically assign the private IP assigned to the Azure virtual machine within the operating system of a VM, unless necessary, such as when assigning multiple IP addresses to a Windows VM. 如果确实需要在操作系统中手动设置该专用 IP 地址,请确保它与分配给 Azure 网络接口的专用 IP 地址是同一地址,否则可能会丢失与虚拟机的连接。If you do manually set the private IP address within the operating system, ensure that it is the same address as the private IP address assigned to the Azure network interface, or you can lose connectivity to the virtual machine. 详细了解专用 IP 地址设置。Learn more about private IP address settings. 切勿在虚拟机的操作系统中手动分配已分配给 Azure 虚拟机的公共 IP 地址。You should never manually assign the public IP address assigned to an Azure virtual machine within the virtual machine's operating system.

如何检索 VM 的静态专用 IP 地址信息How to retrieve static private IP address information for a VM

若要查看使用以上步骤创建的 VM 的静态专用 IP 地址信息,请执行以下步骤。To view the static private IP address information for the VM created with the steps above, execute the following steps.

  1. 在 Azure 门户中,单击“全部浏览” > “虚拟机” > “DNS01” > “所有设置” > “网络接口”,然后单击所列出的唯一网络接口 。From the Azure portal, click BROWSE ALL > Virtual machines > DNS01 > All settings > Network interfaces and then click on the only network interface listed.

    部署 VM 磁贴

  2. 在“网络接口”窗格中,单击“所有设置” > “IP 地址”并几下“分配”和“IP 地址”值 。In the Network interface pane, click All settings > IP addresses and notice the Assignment and IP address values.

    部署 VM 磁贴

如何将静态专用 IP 地址添加到现有 VMHow to add a static private IP address to an existing VM

要将静态专用 IP 地址添加到使用上面步骤创建的 VM 中,请按照以下步骤操作:To add a static private IP address to the VM created using the steps above, follow these steps:

  1. 从上面所示的“IP 地址”窗格中,单击“分配”下的“静态” 。From the IP addresses pane shown above, click Static under Assignment.

  2. 键入 192.168.1.101 作为“IP 地址”,并单击“保存”。Type 192.168.1.101 for IP address, and then click Save.

    在 Azure 门户中创建 VM

Note

单击“保存”后,如果注意到分配仍设置为“动态”,则表示你键入的 IP 地址已被使用 。 请尝试其他 IP 地址。

我们建议,除非有必要(例如,为一个 Windows VM 分配多个 IP 地址时),否则不要以静态方式在 VM 的操作系统中分配已分配给 Azure 虚拟机的专用 IP。It's recommended that you do not statically assign the private IP assigned to the Azure virtual machine within the operating system of a VM, unless necessary, such as when assigning multiple IP addresses to a Windows VM. 如果确实需要在操作系统中手动设置该专用 IP 地址,请确保它与分配给 Azure 网络接口的专用 IP 地址是同一地址,否则可能会丢失与虚拟机的连接。If you do manually set the private IP address within the operating system, ensure that it is the same address as the private IP address assigned to the Azure network interface, or you can lose connectivity to the virtual machine. 详细了解专用 IP 地址设置。Learn more about private IP address settings. 切勿在虚拟机的操作系统中手动分配已分配给 Azure 虚拟机的公共 IP 地址。You should never manually assign the public IP address assigned to an Azure virtual machine within the virtual machine's operating system.

如何从 VM 中删除静态专用 IP 地址How to remove a static private IP address from a VM

若要从上面创建的 VM 中删除静态专用 IP 地址,请完成以下步骤:To remove the static private IP address from the VM created above, complete the following step:

从上面所示的“IP 地址”窗格中,单击“分配”下的“动态”,然后单击“保存” 。From the IP addresses pane shown above, click Dynamic under Assignment, and then click Save.

在操作系统中设置 IP 地址Set IP addresses within the operating system

我们建议,除非有必要(例如,为一个 Windows VM 分配多个 IP 地址时),否则不要以静态方式在 VM 的操作系统中分配已分配给 Azure 虚拟机的专用 IP。It's recommended that you do not statically assign the private IP assigned to the Azure virtual machine within the operating system of a VM, unless necessary, such as when assigning multiple IP addresses to a Windows VM. 如果确实需要在操作系统中手动设置该专用 IP 地址,请确保它与分配给 Azure 网络接口的专用 IP 地址是同一地址,否则可能会丢失与虚拟机的连接。If you do manually set the private IP address within the operating system, ensure that it is the same address as the private IP address assigned to the Azure network interface, or you can lose connectivity to the virtual machine. 详细了解专用 IP 地址设置。Learn more about private IP address settings. 切勿在虚拟机的操作系统中手动分配已分配给 Azure 虚拟机的公共 IP 地址。You should never manually assign the public IP address assigned to an Azure virtual machine within the virtual machine's operating system.

后续步骤Next steps

了解如何管理 IP 地址设置Learn about managing IP address settings.