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.
You can use the Azure portal, the Azure CLI, or Azure PowerShell to dissociate a public IP address from a VM.
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.
- Sign in to the Azure portal.
- Browse to, or search for the virtual machine that you want to disassociate the public IP address from and then select it.
- In the VM page, select Overview, and then select the public IP address.
- In the public IP address page, select Overview, and then select Dissociate.
- In Dissociate public IP address, select Yes.
In this task, you use the az network nic-ip-config update command to dissociate a public IP address from an IP configuration.
Dissociate IP address
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.
# Dissociate the public IP address from the IP configuration
az network nic ip-config update \
--name ipconfigmyVM \
--resource-group myResourceGroup \
--nic-name myVMNic \
--public-ip-address null
Discover name of network interface
If you don't know the name of the network interface attached to your VM, use the 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:
# List the network interfaces attached to a VM
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/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
In the previous example, myVMVic is the name of the network interface.
Discover name of IP configuration
If you don't know the name of the IP configuration of a network interface, use the 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:
# List the IP configurations of a network interface
az network nic ip-config list --nic-name myVMNic --resource-group myResourceGroup --out table
The output is similar to the following example:
Name Primary PrivateIpAddress PrivateIpAddressVersion PrivateIpAllocationMethod ProvisioningState ResourceGroup
------------ --------- ------------------ ------------------------- --------------------------- ------------------- ---------------
ipconfigmyVM True 10.0.0.4 IPv4 Dynamic Succeeded myResourceGroup
In the previous example, ipconfigmyVM is the name of the IP configuration.
Discover name of public IP address
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 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:
# Get the name of public IP address associated to an IP configuration
az network nic ip-config show --name ipconfigmyVM --nic-name myVMNic --resource-group myResourceGroup --query publicIpAddress.id
The output includes one or more lines that are similar to the following example:
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myVMPublicIP",
In the previous example, myVMPublicIP is the name of the public IP address.
In this task, you use the Get-AzNetworkInterface command to get a network interface. 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.
Dissociate IP address
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.
# Dissociate the public IP address from the network interface
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroup myResourceGroup
$nic.IpConfigurations[0].PublicIpAddress = $null
Set-AzNetworkInterface -NetworkInterface $nic
Discover name of network interface
If you don't know the name of the network interface attached to your VM, use the 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:
# Get the network interface attached to a VM
$vm = Get-AzVM -name myVM -ResourceGroupName myResourceGroup
$vm.NetworkProfile
The output includes one or more lines that are similar to the following example:
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic",
In the previous example, myVMNic is the name of the network interface.
Discover name of IP configuration
If you don't know the name of an IP configuration for a network interface, use the 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:
# Get the name of the IP configuration for a network interface
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
$nic.IPConfigurations.Id
The output includes one or more lines that are similar to the following example:
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/myVMNic/ipConfigurations/ipconfigmyVM"
In the previous example, ipconfigmyVM is the name of the IP configuration.
Discover name of public IP address
If you don't know the name of the public IP address associated to an IP configuration, use the 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:
# Get the name of the public IP address associated to an IP configuration
$nic = Get-AzNetworkInterface -Name myVMNic -ResourceGroupName myResourceGroup
$nic.IPConfigurations.PublicIpAddress.Id
The output includes one or more lines that are similar to the following example:
"id": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP"
In the previous example, myVMPublicIP is the name of the public IP address.
In this article, you learned how to dissociate a public IP address from a virtual machine.