Skip to content

Commit 1691852

Browse files
Merge pull request #290447 from mbender-ms/ip-us159269
ip services - Update article with tabs - remove-public-ip-address-vm.md
2 parents d80c67f + bd5811e commit 1691852

File tree

1 file changed

+116
-75
lines changed

1 file changed

+116
-75
lines changed

articles/virtual-network/ip-services/remove-public-ip-address-vm.md

Lines changed: 116 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to dissociate a public IP address from an Azure virtual m
55
services: virtual-network
66
author: mbender-ms
77
ms.author: mbender
8-
ms.date: 08/24/2023
8+
ms.date: 11/19/2024
99
ms.service: azure-virtual-network
1010
ms.subservice: ip-services
1111
ms.topic: how-to
@@ -14,15 +14,38 @@ ms.custom: template-how-to, engagement-fy23, devx-track-azurepowershell, devx-tr
1414

1515
# Dissociate a public IP address from an Azure VM
1616

17-
In this article, you learn how to dissociate a public IP address from an Azure virtual machine (VM). Removing the public IP address of your VM will also remove its ability to connect to the internet.
17+
In this article, you learn how to dissociate a public IP address from an Azure virtual machine (VM). Removing the public IP address of your VM removes access to the Internet.
1818

19-
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.
19+
You can use the Azure portal, the Azure CLI, or Azure PowerShell to dissociate a public IP address from a VM.
2020

2121
## Prerequisites
2222

23+
# [Azure portal](#tab/azureportal)
24+
25+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
26+
- A virtual machine with a public IP address associated to it.
27+
28+
# [Azure CLI](#tab/azurecli/)
29+
2330
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
31+
- A virtual machine with a public IP address associated to it.
32+
- 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.
33+
- If using the CLI locally in Bash, sign in to Azure with `az login`.
34+
35+
# [Azure PowerShell](#tab/azurepowershell/)
36+
37+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
38+
- A virtual machine with a public IP address associated to it.
39+
- Install [PowerShell](/powershell/azure/install-azure-powershell), 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.
40+
- If using PowerShell locally, sign in to Azure with `Connect-AzAccount`.
41+
42+
---
43+
44+
## Dissociate a public IP address from a VM
45+
46+
In this step, you dissociate a public IP address from a virtual machine using the Azure portal, Azure CLI, or Azure PowerShell. The IP address is associated to an IP configuration of a network interface attached to the VM.
2447

25-
## Azure portal
48+
# [Azure portal](#tab/azureportal)
2649

2750
1. Sign in to the [Azure portal](https://portal.azure.com).
2851
2. Browse to, or search for the virtual machine that you want to disassociate the public IP address from and then select it.
@@ -36,127 +59,145 @@ You can use the [Azure portal](#azure-portal), the [Azure CLI](#azure-cli), or [
3659

3760
:::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.":::
3861

39-
## Azure CLI
62+
# [Azure CLI](#tab/azurecli/)
4063

41-
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.
64+
In this task, you 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.
4265

43-
- If using the CLI locally in Bash, sign in to Azure with `az login`.
44-
45-
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.
66+
### Dissociate IP address
4667

4768
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*.
4869

49-
```azurecli-interactive
70+
```azurecli
71+
# Dissociate the public IP address from the IP configuration
5072
az network nic ip-config update \
5173
--name ipconfigmyVM \
5274
--resource-group myResourceGroup \
5375
--nic-name myVMNic \
5476
--public-ip-address null
5577
```
5678

57-
- 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*:
79+
### Discover name of network interface
5880

59-
```azurecli-interactive
60-
az vm nic list --vm-name myVM --resource-group myResourceGroup
61-
```
81+
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*:
6282

63-
The output includes one or more lines that are similar to the following example:
64-
65-
```
66-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
67-
```
83+
```azurecli
84+
# List the network interfaces attached to a VM
85+
az vm nic list --vm-name myVM --resource-group myResourceGroup
86+
```
6887

69-
In the previous example, *myVMVic* is the name of the network interface.
88+
The output includes one or more lines that are similar to the following example:
7089

71-
- 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*:
90+
```
91+
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
92+
```
7293

73-
```azurecli-interactive
74-
az network nic ip-config list --nic-name myVMNic --resource-group myResourceGroup --out table
75-
```
94+
In the previous example, *myVMVic* is the name of the network interface.
7695

77-
The output is similar to the following example:
96+
### Discover name of IP configuration
7897

79-
```
80-
Name Primary PrivateIpAddress PrivateIpAddressVersion PrivateIpAllocationMethod ProvisioningState ResourceGroup
81-
------------ --------- ------------------ ------------------------- --------------------------- ------------------- ---------------
82-
ipconfigmyVM True 10.0.0.4 IPv4 Dynamic Succeeded myResourceGroup
83-
```
98+
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*:
8499

85-
In the previous example, *ipconfigmyVM* is the name of the IP configuration.
100+
```azurecli
101+
# List the IP configurations of a network interface
102+
az network nic ip-config list --nic-name myVMNic --resource-group myResourceGroup --out table
103+
```
86104

87-
- 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*:
105+
The output is similar to the following example:
88106

89-
```azurecli-interactive
90-
az network nic ip-config show --name ipconfigmyVM --nic-name myVMNic --resource-group myResourceGroup --query publicIpAddress.id
91-
```
92-
The output includes one or more lines that are similar to the following example:
93-
94-
```
95-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myVMPublicIP",
96-
```
107+
```
108+
Name Primary PrivateIpAddress PrivateIpAddressVersion PrivateIpAllocationMethod ProvisioningState ResourceGroup
109+
------------ --------- ------------------ ------------------------- --------------------------- ------------------- ---------------
110+
ipconfigmyVM True 10.0.0.4 IPv4 Dynamic Succeeded myResourceGroup
111+
```
112+
113+
In the previous example, *ipconfigmyVM* is the name of the IP configuration.
114+
115+
### Discover name of public IP address
97116

98-
In the previous example, *myVMPublicIP* is the name of the public IP address.
117+
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*:
99118

100-
## PowerShell
119+
```azurecli
120+
# Get the name of public IP address associated to an IP configuration
121+
az network nic ip-config show --name ipconfigmyVM --nic-name myVMNic --resource-group myResourceGroup --query publicIpAddress.id
122+
```
123+
The output includes one or more lines that are similar to the following example:
124+
125+
```
126+
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myVMPublicIP",
127+
```
128+
129+
In the previous example, *myVMPublicIP* is the name of the public IP address.
101130

102-
Install [PowerShell](/powershell/azure/install-azure-powershell), 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.
131+
# [Azure PowerShell](#tab/azurepowershell/)
103132

104-
- If using PowerShell locally, sign in to Azure with `Connect-AzAccount`.
133+
In this task, you 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.
105134

106-
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.
135+
### Dissociate IP address
107136

108137
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*.
109138

110139
```azurepowershell
140+
# Dissociate the public IP address from the network interface
111141
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroup myResourceGroup
112142
$nic.IpConfigurations[0].PublicIpAddress = $null
113143
Set-AzNetworkInterface -NetworkInterface $nic
114144
```
115145

116-
- 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*:
146+
### Discover name of network interface
147+
148+
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*:
149+
150+
```azurepowershell
151+
# Get the network interface attached to a VM
152+
$vm = Get-AzVM -name myVM -ResourceGroupName myResourceGroup
153+
$vm.NetworkProfile
154+
```
155+
156+
The output includes one or more lines that are similar to the following example:
157+
158+
```
159+
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
160+
```
117161

118-
```azurepowershell
119-
$vm = Get-AzVM -name myVM -ResourceGroupName myResourceGroup
120-
$vm.NetworkProfile
121-
```
162+
In the previous example, *myVMNic* is the name of the network interface.
122163

123-
The output includes one or more lines that are similar to the following example:
164+
### Discover name of IP configuration
124165

125-
```
126-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
127-
```
166+
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*:
128167

129-
In the previous example, *myVMNic* is the name of the network interface.
168+
```azurepowershell
169+
# Get the name of the IP configuration for a network interface
170+
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
171+
$nic.IPConfigurations.Id
172+
```
130173

131-
- 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*:
174+
The output includes one or more lines that are similar to the following example:
132175

133-
```azurepowershell-interactive
134-
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
135-
$nic.IPConfigurations.Id
136-
```
176+
```
177+
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic/ipConfigurations/ipconfigmyVM"
178+
```
137179

138-
The output includes one or more lines that are similar to the following example:
180+
In the previous example, *ipconfigmyVM* is the name of the IP configuration.
139181

140-
```
141-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic/ipConfigurations/ipconfigmyVM"
142-
```
182+
### Discover name of public IP address
143183

144-
In the previous example, *ipconfigmyVM* is the name of the IP configuration.
184+
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*:
145185

146-
- 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*:
186+
```azurepowershell
187+
# Get the name of the public IP address associated to an IP configuration
188+
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
189+
$nic.IPConfigurations.PublicIpAddress.Id
190+
```
147191

148-
```azurepowershell-interactive
149-
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
150-
$nic.IPConfigurations.PublicIpAddress.Id
151-
```
192+
The output includes one or more lines that are similar to the following example:
152193

153-
The output includes one or more lines that are similar to the following example:
194+
```
195+
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP"
196+
```
154197

155-
```
156-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP"
157-
```
198+
In the previous example, *myVMPublicIP* is the name of the public IP address.
158199

159-
In the previous example, *myVMPublicIP* is the name of the public IP address.
200+
---
160201

161202
## Next steps
162203

0 commit comments

Comments
 (0)