Use PowerShell to Create a Reserved Virtual IP Address (VIP) in Azure

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.

azure-ip1a

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:

azure-ip2a

The same cmdlet can be used to determine how many virtual IP addresses you’ve already reserved in Azure:

azure-ip3a

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:

azure-ip4a

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.

µ

4 Comments

  1. vernanderson

    Thank you Mike! Hope you’re doing well!

    Reply
  2. mcosier

    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

    Reply
  3. Mijail Cuesta

    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!

    Reply

Leave a Reply

%d bloggers like this: