将公共 IP 地址与 Azure VM 取消关联Dissociate a public IP address from an Azure VM

本文介绍如何将公共 IP 地址与 Azure 虚拟机 (VM) 取消关联。In this article, you learn how to dissociate a public IP address from an Azure virtual machine (VM).

可以使用 Azure 门户、Azure 命令行接口 (CLI) 或 PowerShell 将公共 IP 地址与 VM 取消关联。You can use the Azure portal, the Azure command-line interface (CLI), or PowerShell to dissociate a public IP address from a VM.

Azure 门户Azure portal

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 浏览或搜索要将公共 IP 地址与之取消关联的虚拟机,然后将其选中。Browse to, or search for the virtual machine that you want to disassociate the public IP address from and then select it.

  3. 在 VM 页中选择“概述”,然后选择公共 IP 地址,如下图所示:In the VM page, select Overview, select the public IP address as shown in the following picture:

    选择公共 IP

  4. 在公共 IP 地址页中选择“概述”,然后选择“取消关联”,如下图所示:In the public IP address page, select Overview, and then select Dissociate, as shown in the following picture:

    取消关联公共 IP

  5. 在“取消关联公共 IP 地址”中,选择“是”。In Dissociate public IP address, select Yes.

Azure CLIAzure CLI

安装 Azure CLIInstall the Azure CLI

备注

请先运行 az cloud set -n AzureChinaCloud 更改云环境,然后才能在 Azure 中国中使用 Azure CLI。Before you can use Azure CLI in Azure China , please run az cloud set -n AzureChinaCloud first to change the cloud environment. 若要切换回 Azure 公有云,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Azure Public Cloud, run az cloud set -n AzureCloud again.

  1. 如果在本地使用 CLI,请使用 az login 登录到 Azure。When using the CLI locally, sign in to Azure with az login.

    az cloud set -n AzureChinaCloud
    az login
    
  2. 公共 IP 地址将关联到 VM 上附加的网络接口的 IP 配置。A public IP address is associated to an IP configuration of a network interface attached to a VM. 使用 az network nic-ip-config update 命令将公共 IP 地址与 IP 配置取消关联。Use the az network nic-ip-config update command to dissociate a public IP address from an IP configuration. 以下示例将名为 myVMPublicIP 的公共 IP 地址与名为 myVMVMNic 的现有网络接口(已连接到名为 myResourceGroup 的资源组中名为 myVM 的 VM)的名为 ipconfigmyVM 的 IP 配置取消关联。The following example dissociates a public IP address named myVMPublicIP from the IP configuration named ipconfigmyVM of an existing network interface named myVMVMNic that is attached to a VM named myVM in a resource group named myResourceGroup.

    az network nic ip-config update \
    --name ipconfigmyVM \
    --resource-group myResourceGroup \
    --nic-name myVMVMNic \
    --remove PublicIpAddress
    

    如果你不知道附加到 VM 的网络接口的名称,请使用 az vm nic list 命令查看名称。If you don't know the name of a network interface attached to your VM, use the az vm nic list command to view them. 例如,以下命令会列出附加到资源组 myResourceGroup 中 VM myVM 的网络接口的名称:For example, the following command lists the names of the network interfaces attached to a VM named myVM in a resource group named myResourceGroup:

    az vm nic list --vm-name myVM --resource-group myResourceGroup
    

    输出中包含类似于以下示例的一个或多个行:The output includes one or more lines that are similar to the following example:

    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic",
    

    在以上示例中,myVMVMNic 是网络接口的名称。In the previous example, myVMVMNic is the name of the network interface.

    • 如果你不知道网络接口的 IP 配置的名称,请使用 az network nic ip-config list 命令检索名称。If you don't know the name of an IP configuration for a network interface, use the az network nic ip-config list command to retrieve them. 例如,以下命令列出了名为 myResourceGroup 的资源组中名为 myVMVMNic 的网络接口的公共 IP 配置的名称:For example, the following command lists the names of the public IP configurations for a network interface named myVMVMNic in a resource group named myResourceGroup:

      az network nic ip-config list --nic-name myVMVMNic --resource-group myResourceGroup --out table
      
    • 如果不知道网络接口的公共 IP 配置的名称,请使用 az network nic ip-config show 命令进行检索。If you don't know the name of a public IP configuration for a network interface, use the az network nic ip-config show command to retrieve them. 例如,以下命令列出了名为 myResourceGroup 的资源组中名为 myVMVMNic 的网络接口的公共 IP 配置的名称:For example, the following command lists the names of the public IP configurations for a network interface named myVMVMNic in a resource group named myResourceGroup:

      az network nic ip-config show --name ipconfigmyVM --nic-name myVMVMNic --resource-group myResourceGroup --query publicIPAddress.id
      

PowerShellPowerShell

安装 PowerShellInstall PowerShell.

  1. 如果在本地以管理员权限使用 PowerShell,请使用 Connect-AzAccount -Environment AzureChinaCloud 登录到 Azure。When using PowerShell locally with administor priviledge, sign in to Azure with Connect-AzAccount -Environment AzureChinaCloud.

  2. 公共 IP 地址将关联到 VM 上附加的网络接口的 IP 配置。A public IP address is associated to an IP configuration of a network interface attached to a VM. 使用 Get-AzNetworkInterface 命令获取网络接口。Use the Get-AzNetworkInterface command to get a network interface. 将公共 IP 地址值设置为 null,然后使用 Set-AzNetworkInterface 命令将新 IP 配置写入网络接口。Set the Public IP address value to null and then use the Set-AzNetworkInterface command to write the new IP configuration to the network interface.

    以下示例将名为 myVMPublicIP 的公共 IP 地址与连接到名为 myVM 的 VM 的名为 myVMVMNic 的网络接口取消关联。The following example dissociates a public IP address named myVMPublicIP from a network interface named myVMVMNic that is attached to a VM named myVM. 所有资源位于名为 myResourceGroup 的资源组中。All resources are in a resource group named myResourceGroup.

    $nic = Get-AzNetworkInterface -Name myVMVMNic -ResourceGroup myResourceGroup
    $nic.IpConfigurations.publicipaddress.id = $null
    Set-AzNetworkInterface -NetworkInterface $nic
    
    • 如果你不知道附加到 VM 的网络接口的名称,请使用 Get-AzVM 命令查看名称。If you don't know the name of a network interface attached to your VM, use the Get-AzVM command to view them. 例如,以下命令会列出附加到资源组 myResourceGroup 中 VM myVM 的网络接口的名称:For example, the following command lists the names of the network interfaces attached to a VM named myVM in a resource group named myResourceGroup:

      $vm = Get-AzVM -name myVM -ResourceGroupName myResourceGroup
      $vm.NetworkProfile
      

      输出中包含类似于以下示例的一个或多个行。The output includes one or more lines that are similar to the example that follows. 在示例输出中,myVMVMNic 是网络接口的名称。In the example output, myVMVMNic is the name of the network interface.

      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic",
      
    • 如果你不知道网络接口的 IP 配置的名称,请使用 Get-AzNetworkInterface 命令检索名称。If you don't know the name of an IP configuration for a network interface, use the Get-AzNetworkInterface command to retrieve them. 例如,以下命令会列出资源组 myResourceGroup 中网络接口 myVMVMNic 的 IP 配置的名称:For example, the following command lists the names of the IP configurations for a network interface named myVMVMNic in a resource group named myResourceGroup:

      $nic = Get-AzNetworkInterface -Name myVMVMNic -ResourceGroupName myResourceGroup
      $nic.IPConfigurations.id
      

      输出中包含类似于以下示例的一个或多个行。The output includes one or more lines that are similar to the example that follows. 在示例输出中,ipconfigmyVM 是 IP 配置的名称。In the example output, ipconfigmyVM is the name of an IP configuration.

      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic/ipConfigurations/ipconfigmyVM"
      

后续步骤Next steps