Skip to content

Commit 7595030

Browse files
Merge pull request #221809 from halkazwini/ip-del
Virtual Network: Freshness: Dissociate a public IP address from an Azure VM
2 parents df20aaa + 5dff857 commit 7595030

File tree

3 files changed

+112
-64
lines changed

3 files changed

+112
-64
lines changed
110 KB
Loading
58.1 KB
Loading
Lines changed: 112 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
---
22
title: Dissociate a public IP address from an Azure VM
33
titlesuffix: Azure Virtual Network
4-
description: Learn how to dissociate a public IP address from a VM
4+
description: Learn how to dissociate a public IP address from an Azure virtual machine (VM) using the Azure portal, Azure CLI or Azure PowerShell.
55
services: virtual-network
6-
documentationcenter: ''
76
author: asudbring
87
ms.service: virtual-network
98
ms.subservice: ip-services
109
ms.topic: how-to
11-
ms.tgt_pltfrm: na
1210
ms.workload: infrastructure-services
13-
ms.date: 12/04/2019
11+
ms.date: 12/16/2022
1412
ms.author: allensu
15-
13+
ms.custom: template-how-to, engagement-fy23
1614
---
1715

1816
# Dissociate a public IP address from an Azure VM
@@ -21,103 +19,153 @@ In this article, you learn how to dissociate a public IP address from an Azure v
2119

2220
You can use the [Azure portal](#azure-portal), the [Azure CLI](#azure-cli), or [Azure PowerShell](#powershell) to dissociate a public IP address from a VM.
2321

22+
## Prerequisites
23+
24+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
25+
2426
## Azure portal
2527

2628
1. Sign in to the [Azure portal](https://portal.azure.com).
2729
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:
30+
3. In the VM page, select **Overview**, and then select the public IP address.
2931

30-
![Select Public IP](./media/remove-public-ip-address/remove-public-ip-address-2.png)
32+
:::image type="content" source="./media/remove-public-ip-address-vm/vm-public-ip.png" alt-text="Screenshot of the Overview page of a virtual machine showing of the public IP.":::
3133

32-
4. In the public IP address page, select **Overview**, and then select **Dissociate**, as shown in the following picture:
33-
34-
![Dissociate Public IP](./media/remove-public-ip-address/remove-public-ip-address-3.png)
34+
4. In the public IP address page, select **Overview**, and then select **Dissociate**.
3535

3636
5. In **Dissociate public IP address**, select **Yes**.
3737

38+
:::image type="content" source="./media/remove-public-ip-address-vm/dissociate-public-ip.png" alt-text="Screenshot of the Overview page of a public IP address resource showing how to dissociate it from the network interface of a virtual machine.":::
39+
3840
## Azure CLI
3941

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.
42+
Install the [Azure CLI](/cli/azure/install-azure-cli), or use the [Azure Cloud Shell](../../cloud-shell/overview.md). The Azure Cloud Shell is a free shell that you can run directly within the Azure portal. It has the Azure CLI preinstalled and configured to use with your account.
4143

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#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 PublicIpAddress
51-
```
44+
- If using the CLI locally in Bash, sign in to Azure with `az login`.
5245

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#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*:
46+
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#az-network-nic-ip-config-update) command to dissociate a public IP address from an IP configuration.
5447

55-
```azurecli-interactive
56-
az vm nic list --vm-name myVM --resource-group myResourceGroup
57-
```
48+
The following example dissociates a public IP address named *myVMPublicIP* from an IP configuration named *ipconfigmyVM* of an existing network interface named *myVMNic* that is attached to a VM named *myVM* in a resource group named *myResourceGroup*.
49+
50+
```azurecli-interactive
51+
az network nic ip-config update \
52+
--name ipconfigmyVM \
53+
--resource-group myResourceGroup \
54+
--nic-name myVMNic \
55+
--public-ip-address ''
56+
```
57+
58+
- If you don't know the name of the network interface attached to your VM, use the [az vm nic list](/cli/azure/vm/nic#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*:
59+
60+
```azurecli-interactive
61+
az vm nic list --vm-name myVM --resource-group myResourceGroup
62+
```
5863
59-
The output includes one or more lines that are similar to the following example:
64+
The output includes one or more lines that are similar to the following example:
6065
61-
```
62-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic",
63-
```
66+
```
67+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
68+
```
69+
70+
In the previous example, *myVMVic* is the name of the network interface.
6471
65-
In the previous example, *myVMVMNic* is the name of the network interface.
72+
- If you don't know the name of the IP configuration of a network interface, use the [az network nic ip-config list](/cli/azure/network/nic/ip-config#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 *myVMNic* in a resource group named *myResourceGroup*:
6673
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#az-network-nic-ip-config-list) command to retrieve them. 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*:
74+
```azurecli-interactive
75+
az network nic ip-config list --nic-name myVMNic --resource-group myResourceGroup --out table
76+
```
6877
69-
```azurecli-interactive
70-
az network nic ip-config list --nic-name myVMVMNic --resource-group myResourceGroup --out table
71-
```
78+
The output is similar to the following example:
7279
73-
- If you don't know the name of a public IP configuration for a network interface, use the [az network nic ip-config show](/cli/azure/network/nic/ip-config#az-network-nic-ip-config-show) command to retrieve them. 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*:
80+
```
81+
Name Primary PrivateIpAddress PrivateIpAddressVersion PrivateIpAllocationMethod ProvisioningState ResourceGroup
82+
------------ --------- ------------------ ------------------------- --------------------------- ------------------- ---------------
83+
ipconfigmyVM True 10.0.0.4 IPv4 Dynamic Succeeded myResourceGroup
84+
```
7485
75-
```azurecli-interactive
76-
az network nic ip-config show --name ipconfigmyVM --nic-name myVMVMNic --resource-group myResourceGroup --query publicIPAddress.id
77-
```
86+
In the previous example, *ipconfigmyVM* is the name of the IP configuration.
7887
88+
- If you don't know the name of the public IP address associated to an IP configuration, use the [az network nic ip-config show](/cli/azure/network/nic/ip-config#az-network-nic-ip-config-show) command to retrieve them. For example, the following command lists the names of the public IP addresses for a network interface named *myVMNic* in a resource group named *myResourceGroup*:
89+
90+
```azurecli-interactive
91+
az network nic ip-config show --name ipconfigmyVM --nic-name myVMNic --resource-group myResourceGroup --query publicIpAddress.id
92+
```
93+
The output includes one or more lines that are similar to the following example:
94+
95+
```
96+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myVMPublicIP",
97+
```
98+
99+
In the previous example, *myVMPublicIP* is the name of the public IP address.
79100
80101
## PowerShell
81102
82-
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.
103+
Install [PowerShell](/powershell/azure/install-az-ps), or use the [Azure Cloud Shell](../../cloud-shell/overview.md). 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.
83104
84-
1. If using PowerShell locally, sign in to Azure with `Connect-AzAccount`.
85-
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.
105+
- If using PowerShell locally, sign in to Azure with `Connect-AzAccount`.
86106
87-
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*.
107+
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.
108+
109+
The following example dissociates a public IP address named *myVMPublicIP* from a network interface named *myVMNic* that is attached to a VM named *myVM*. All resources are in a resource group named *myResourceGroup*.
88110
89-
```azurepowershell
90-
$nic = Get-AzNetworkInterface -Name myVMVMNic -ResourceGroup myResourceGroup
91-
$nic.IpConfigurations.publicipaddress.id = $null
92-
Set-AzNetworkInterface -NetworkInterface $nic
93-
```
111+
```azurepowershell
112+
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroup myResourceGroup
113+
$nic.IpConfigurations.publicipaddress.id = $null
114+
Set-AzNetworkInterface -NetworkInterface $nic
115+
```
94116

95-
- 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*:
117+
- If you don't know the name of the 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*:
96118

97119
```azurepowershell
98120
$vm = Get-AzVM -name myVM -ResourceGroupName myResourceGroup
99121
$vm.NetworkProfile
100122
```
101123
102-
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.
103-
104-
```
105-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic",
106-
```
124+
The output includes one or more lines that are similar to the following example:
107125
108-
- 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*:
126+
```
127+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
128+
```
109129
110-
```azurepowershell-interactive
111-
$nic = Get-AzNetworkInterface -Name myVMVMNic -ResourceGroupName myResourceGroup
112-
$nic.IPConfigurations.id
113-
```
130+
In the previous example, *myVMNic* is the name of the network interface.
114131
115-
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.
116-
117-
```
118-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMVMNic/ipConfigurations/ipconfigmyVM"
119-
```
132+
- 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 *myVMNic* in a resource group named *myResourceGroup*:
133+
134+
```azurepowershell-interactive
135+
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
136+
$nic.IPConfigurations.Id
137+
```
138+
139+
The output includes one or more lines that are similar to the following example:
140+
141+
```
142+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic/ipConfigurations/ipconfigmyVM"
143+
```
144+
145+
In the previous example, *ipconfigmyVM* is the name of the IP configuration.
146+
147+
- If you don't know the name of the public IP address associated to an IP configuration, use the [Get-AzNetworkInterface](/powershell/module/Az.Network/Get-AzNetworkInterface) command to retrieve them. For example, the following command lists the name of the public IP addresses for a network interface named *myVMNic* in a resource group named *myResourceGroup*:
148+
149+
```azurepowershell-interactive
150+
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
151+
$nic.IPConfigurations.PublicIpAddress.Id
152+
```
153+
154+
The output includes one or more lines that are similar to the following example:
155+
156+
```
157+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP"
158+
```
159+
160+
In the previous example, *myVMPublicIP* is the name of the public IP address.
120161
121162
## Next steps
122163
123-
- Learn how to [associate a public IP address to a VM](associate-public-ip-address-vm.md).
164+
In this article, you learned how to dissociate a public IP address from a virtual machine.
165+
166+
- Learn more about [public IP addresses](./public-ip-addresses.md) in Azure.
167+
168+
- Learn how to [associate a public IP address to a VM](./associate-public-ip-address-vm.md).
169+
170+
- Learn how to [configure IP addresses for an Azure network interface](./virtual-network-network-interface-addresses.md).
171+

0 commit comments

Comments
 (0)