使用 Azure 门户为虚拟机(经典)配置专用 IP 地址Configure private IP addresses for a virtual machine (Classic) 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.

本文介绍经典部署模型。This article covers the classic deployment model. 还可以在 Resource Manager 部署模型中管理静态专用 IP 地址You can also manage a static private IP address in the Resource Manager 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 sample steps that follow expect a simple environment already created. 如果想要运行本文档中所显示的步骤,首先需要生成创建 Vnet 中所述的测试环境。If you want to run the steps as they are displayed in this document, first build the test environment described in create a vnet.

如何在创建 VM 时指定静态专用 IP 地址How to specify a static private IP address when creating a VM

若要在名为 TestVNet 的 VNet 的 FrontEnd 子网中使用静态专用 IP 192.168.1.101 创建名为 DNS01 的 VM,请完成以下步骤:To create a VM named DNS01 in the FrontEnd subnet of a VNet named TestVNet with a static private IP of 192.168.1.101, complete the following 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 Datacenter”(注意“选择部署模型”列表已显示“经典”),然后选择“创建”。Select NEW > Compute > Windows Server 2012 R2 Datacenter, notice that the Select a deployment model list already shows Classic, and then select Create.

    在 Azure 门户中创建 VM

  3. 在“创建 VM” 下,输入要创建的 VM 的名称(在此方案中为 DNS01)、本地管理员帐户和密码。Under Create VM, enter the name of the VM to be created (DNS01 in the scenario), the local administrator account, and password.

    在 Azure 门户中创建 VM

  4. 选择“可选配置” > “网络” > “虚拟网络”,然后选择“TestVNet”。Select Optional Configuration > Network > Virtual Network, and then select TestVNet. 如果 TestVNet 不可用,请确保你使用的位置为“中国北部”,并已创建本文开头所述的测试环境。 If TestVNet is not available, make sure you are using the China North location and have created the test environment described at the beginning of this article.

    在 Azure 门户中创建 VM

  5. 在“网络”下,确保当前选定的子网为“FrontEnd”,选择“IP 地址”,在“IP 地址分配”下选择“静态”,并输入 192.168.1.101 作为“IP 地址”,如下所示。Under Network, make sure the subnet currently selected is FrontEnd, then select IP addresses, under IP address assignment select Static, and then enter 192.168.1.101 for IP Address as seen below.

    在 Azure 门户中创建 VM

  6. 在“IP 地址”下选择“确定”,在“网络”下选择“确定”,然后在“可选配置”下选择“确定”。 Select OK under IP addresses, select OK under Network, and then select OK under Optional config.

  7. 在“创建 VM”下,选择“创建”。 Under Create VM, select Create. 注意,以下磁贴会显示在仪表板中:Notice the tile below displayed in your dashboard:

    在 Azure 门户中创建 VM

如何检索 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 steps below.

  1. 在 Azure 门户中,选择“浏览全部” > “虚拟机(经典)” > “DNS01” > “所有设置” > “IP 地址”,并请注意如下所示的 IP 地址分配和 IP 地址。From the Azure portal, select BROWSE ALL > Virtual machines (classic) > DNS01 > All settings > IP addresses and notice the IP address assignment and IP address as seen below.

    在 Azure 门户中创建 VM

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

在“IP 地址”下,在“IP 地址分配”右侧选择“动态”,选择“保存”,然后选择“是”,如下图中所示:Under IP addresses, select Dynamic to the right of IP address assignment, select Save, and then select Yes, as shown in the following picture:

![Create VM in Azure portal](./media/virtual-networks-static-ip-classic-pportal/figure07.png)

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

  1. 在前面显示的“IP 地址”下,在“IP 地址分配”右侧选择“静态”。Under IP addresses, shown previously, select Static to the right of IP address assignment.
  2. 对于“IP 地址”,键入 192.168.1.101,选择“保存”,然后选择“是”。 Type 192.168.1.101 for IP address, select Save, and then select Yes.

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

我们建议,除非有必要,否则不要以静态方式在 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. 如果确实需要在操作系统中手动设置该专用 IP 地址,请确保它是分配给 Azure VM 的同一专用 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 VM, or you can lose connectivity to the virtual machine. 切勿在虚拟机的操作系统中手动分配已分配给 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