|
| 1 | +--- |
| 2 | +title: Dissociate a public IP address from an Azure VM |
| 3 | +titlesuffix: Azure Virtual Network |
| 4 | +description: Learn how to dissociate a public IP address from a VM |
| 5 | +services: virtual-network |
| 6 | +documentationcenter: '' |
| 7 | +author: KumudD |
| 8 | +ms.service: virtual-network |
| 9 | +ms.devlang: na |
| 10 | +ms.topic: article |
| 11 | +ms.tgt_pltfrm: na |
| 12 | +ms.workload: infrastructure-services |
| 13 | +ms.date: 12/04/2019 |
| 14 | +ms.author: kumud |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +# Dissociate a public IP address from an Azure VM |
| 19 | + |
| 20 | +In this article, you learn how to dissociate a public IP address from an Azure virtual machine (VM). |
| 21 | + |
| 22 | +You can use the [Azure portal](#azure-portal), the Azure [command-line interface](#azure-cli) (CLI), or [PowerShell](#powershell) to dissociate a public IP address from a VM. |
| 23 | + |
| 24 | +## Azure portal |
| 25 | + |
| 26 | +1. Sign in to the [Azure portal](https://portal.azure.com). |
| 27 | +2. Browse to, or search for the virtual machine that you want to disassociate the public IP address from and then select it. |
| 28 | +3. In the VM page, select **Overview**, select the public IP address as shown in the following picture: |
| 29 | + |
| 30 | +  |
| 31 | + |
| 32 | +4. In the public IP address page, select **Overview**, and then select **Dissociate**, as shown in the following picture: |
| 33 | + |
| 34 | +  |
| 35 | + |
| 36 | +5. In **Dissociate public IP address**, select **Yes**. |
| 37 | + |
| 38 | +## Azure CLI |
| 39 | + |
| 40 | +Install the [Azure CLI](/cli/azure/install-azure-cli?toc=%2fazure%2fvirtual-network%2ftoc.json), or use the Azure Cloud Shell. The Azure Cloud Shell is a free Bash shell that you can run directly within the Azure portal. It has the Azure CLI preinstalled and configured to use with your account. Select the **Try it** button in the CLI commands that follow. Selecting **Try it** invokes a Cloud Shell that you can sign in to your Azure account with. |
| 41 | + |
| 42 | +1. If using the CLI locally in Bash, sign in to Azure with `az login`. |
| 43 | +2. A public IP address is associated to an IP configuration of a network interface attached to a VM. Use the [az network nic-ip-config update](/cli/azure/network/nic/ip-config?view=azure-cli-latest#az-network-nic-ip-config-update) command to dissociate a public IP address from an IP configuration. 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*. |
| 44 | + |
| 45 | + ```azurecli-interactive |
| 46 | + az network nic ip-config update \ |
| 47 | + --name ipconfigmyVM \ |
| 48 | + --resource-group myResourceGroup \ |
| 49 | + --nic-name myVMVMNic \ |
| 50 | + --remove PublicIpAdress |
| 51 | + ``` |
| 52 | + |
| 53 | + If you don't know the name of a network interface attached to your VM, use the [az vm nic list](/cli/azure/vm/nic?view=azure-cli-latest#az-vm-nic-list) command to view them. For example, the following command lists the names of the network interfaces attached to a VM named *myVM* in a resource group named *myResourceGroup*: |
| 54 | + |
| 55 | + ```azurecli-interactive |
| 56 | + az vm nic list --vm-name myVM --resource-group myResourceGroup |
| 57 | + ``` |
| 58 | +
|
| 59 | + The output includes one or more lines that are similar to the following example: |
| 60 | + |
| 61 | + ``` |
| 62 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic", |
| 63 | + ``` |
| 64 | +
|
| 65 | + In the previous example, *myVMVMNic* is the name of the network interface. |
| 66 | +
|
| 67 | + - If you don't know the name of an IP configuration for a network interface, use the [az network nic ip-config list](/cli/azure/network/nic/ip-config?view=azure-cli-latest#az-network-nic-ip-config-list) command to retrieve them. For example, the following command lists the names of the IP configurations for a network interface named *myVMVMNic* in a resource group named *myResourceGroup*: |
| 68 | +
|
| 69 | + ```azurecli-interactive |
| 70 | + az network nic ip-config list --nic-name myVMVMNic --resource-group myResourceGroup --out table |
| 71 | + ``` |
| 72 | +
|
| 73 | +## PowerShell |
| 74 | +
|
| 75 | +Install [PowerShell](/powershell/azure/install-az-ps), or use the Azure Cloud Shell. The Azure Cloud Shell is a free shell that you can run directly within the Azure portal. It has PowerShell preinstalled and configured to use with your account. Select the **Try it** button in the PowerShell commands that follow. Selecting **Try it** invokes a Cloud Shell that you can sign in to your Azure account with. |
| 76 | +
|
| 77 | +1. If using PowerShell locally, sign in to Azure with `Connect-AzAccount`. |
| 78 | +2. A public IP address is associated to an IP configuration of a network interface attached to a VM. Use the [Get-AzNetworkInterface](/powershell/module/Az.Network/Get-AzNetworkInterface) command to get a network interface. Set the Public IP address value to null and then use the [Set-AzNetworkInterface](/powershell/module/Az.Network/Set-AzNetworkInterface) command to write the new IP configuration to the network interface. |
| 79 | +
|
| 80 | + The following example dissociates a public IP address named *myVMPublicIP* from a network interface named *myVMVMNic* that is attached to a VM named *myVM*. All resources are in a resource group named *myResourceGroup*. |
| 81 | + |
| 82 | + ```azurepowershell |
| 83 | + $nic = Get-AzNetworkInterface -Name myVMVMNic -ResourceGroup myResourceGroup |
| 84 | + $nic.IpConfigurations.publicipaddress.id = $null |
| 85 | + Set-AzNetworkInterface -NetworkInterface $nic |
| 86 | + ``` |
| 87 | + |
| 88 | + - If you don't know the name of a network interface attached to your VM, use the [Get-AzVM](/powershell/module/Az.Compute/Get-AzVM) command to view them. For example, the following command lists the names of the network interfaces attached to a VM named *myVM* in a resource group named *myResourceGroup*: |
| 89 | + |
| 90 | + ```azurepowershell |
| 91 | + $vm = Get-AzVM -name myVM -ResourceGroupName myResourceGroup |
| 92 | + $vm.NetworkProfile |
| 93 | + ``` |
| 94 | +
|
| 95 | + The output includes one or more lines that are similar to the example that follows. In the example output, *myVMVMNic* is the name of the network interface. |
| 96 | + |
| 97 | + ``` |
| 98 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic", |
| 99 | + ``` |
| 100 | +
|
| 101 | + - If you don't know the name of an IP configuration for a network interface, use the [Get-AzNetworkInterface](/powershell/module/Az.Network/Get-AzNetworkInterface) command to retrieve them. For example, the following command lists the names of the IP configurations for a network interface named *myVMVMNic* in a resource group named *myResourceGroup*: |
| 102 | +
|
| 103 | + ```azurepowershell-interactive |
| 104 | + $nic = Get-AzNetworkInterface -Name myVMVMNic -ResourceGroupName myResourceGroup |
| 105 | + $nic.IPConfigurations |
| 106 | + ``` |
| 107 | +
|
| 108 | + The output includes one or more lines that are similar to the example that follows. In the example output, *ipconfigmyVM* is the name of an IP configuration. |
| 109 | + |
| 110 | + ``` |
| 111 | + Id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic/ipConfigurations/ipconfigmyVM |
| 112 | + ``` |
| 113 | +
|
| 114 | +## Next steps |
| 115 | +
|
| 116 | +- Learn how to [associate a public IP address to a VM](associate-public-ip-address-vm.md). |
0 commit comments