By default, the VM’s that you create in Azure will have a dynamic virtual IP address (VIP). Based on this article on Azure, you could simply create a DNS CNAME record for your custom domain and point it to the DNS name that you chose during the creation of your azure VM which should prevent any problems if the virtual IP address happens to change.
Maybe you want a reserved virtual IP address for your Azure instance though? There’s a limited number of reserved virtual IP addresses per subscription so make sure you use them sparingly if you do indeed want to create and use reserved virtual IP addresses.
1 | New-AzureReservedIP –ReservedIPName 'mikefrobbinsIP' –Location 'South Central US' |
The Get-AzureReservedIP PowerShell cmdlet can be used to see the actual IP address once the reservation has been created. For security reasons, I’ve blurred out the actual IP address that was created in the following example:
1 | Get-AzureReservedIP –ReservedIPName 'mikefrobbinsIP' |
The same cmdlet can be used to determine how many virtual IP addresses you’ve already reserved in Azure:
1 | (Get-AzureReservedIP).count |
One of the catches is that you can’t assign a reserved virtual IP address to a VM that already exists in Azure. Based on what I’ve read this is something that they’re working on so it is subject to change.
The Remove-AzureReservedIP cmdlet is used to remove a reserved virtual IP address. If it’s currently in use (associated with an Azure cloud service), the removal will fail:
1 | Get-AzureReservedIP -ReservedIPName mikefrobbinsIP | Remove-AzureReservedIP |
Remove-AzureReservedIP : BadRequest: The Reserved IP mikefrobbinsIP is currently in use by Deployment
mikefrobbins-test belonging to HostedService mikefrobbins-test.
At line:1 char:54
+ … ureReservedIP -ReservedIPName mikefrobbinsIP | Remove-AzureReservedIP
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzureReservedIP], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.RemoveAzureReservedIPCmdlet
Based on my testing, even if you delete the VM and the Cloud Service that the reserved virtual IP address is associated with, the IP will remain reserved and associated with your Azure subscription.
Recommended reading on MSDN: VIPs, DIPs and PIPs in Microsoft Azure and Reserved IP Addresses.
µ
Thank you Mike! Hope you’re doing well!
You mention that you can’t remove the reserved IP. Generally you can, you just need to make sure you explicitly perform an Remove-AzureDeployment in both -Slot “Production” and -Slot “Staging” – if you only do one of them, and you had done a VIP swap at any stage, then it will ‘hold onto it’, otherwise you can easily remove it.
HTH someone else,
Matthew Cosier
Hi, do you know any cmdlets to get a new VIP from the pool, renewing it from the VM but without having to restart it using Stop and Start-AzureRmVM commands to accomplish this? I want to change the public IP, regularly. If you know the way, please tell me how.. Thanks!