16

Azure CLI: Delete Public IP From Existing NIC / VM | Build5Nines

 2 years ago
source link: https://build5nines.com/azure-cli-delete-public-ip-from-existing-nic-vm/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Azure CLI: Delete Public IP from Existing NIC / VM

By Chris Pietschmann | February 16, 2022 - 3:48 PM CST (21:48 UTC)
Category: Azure CLI Kung Fu
Azure CLI: Delete Public IP from Existing NIC / VM

So you have already created a Virtual Machine in Azure that is provisioned with a Public IP address and you need to remove it. Don’t worry, you do NOT need to delete the VM. You can disassociate the Public IP from the Network Interface connected to the VM, and then delete the Public IP. This can easily be done using the Azure CLI.

Below is a simple script that will use the az network nic ip-config update command to disassociate the Public IP from the Network Interface so it’s no longer assigned and being used. Then, the script will use the az network public-ip delete command to delete the Public IP since it’s no longer needed anymore.

resourceGroupName="myRG"
nicName="myVMNic"
publicIp="myPublicIp"
publicIpNameOnNic="ipconfig1"

# Disassociate the Public IP Address from the NIC first
az network nic ip-config update \
  --resource-group $resourceGroupName --nic-name $nicName \
  --name $publicIpNameOnNic --remove PublicIpAddress

# Delete the Public IP
az network public-ip delete -g $resourceGroupName -n $publicIp

Keep in mind that if you don’t want to delete the Public IP, but only disassociate it from the Network Interface, you could just do that first step. Then you’ll have a disconnected Public IP resource within your resource group. This may be desired if you have the Public IP to have a static IP Address that you don’t want to lose. After all, if the Public IP address has a static IP Address configured, you will lose control / access to that Public IP Address by deleting the Public IP resource itself.

Happy scripting!

About the Author

Chris Pietschmann

Chris is the Founder of Build5Nines.com and a Microsoft MVP in Azure & IoT with 20 years of experience designing and building Cloud & Enterprise systems. He is also a Microsoft Certified: Azure Solutions Architect, developer, Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.

Leave a Comment Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK