Monday, 30 March 2015

Microsoft Azure and public IP reservation woes

By default Azure does not assign perminent public IP addresses - when the Stop-VM cmdlet / shutdown is invoked the VM looses it's public IP address, in order to work around this we can either use CNAME records (although this won't work for the root domain as CNAME records can't be applied to for example - only or we can make use of a "Reserved IP" provided by Azure.

New-AzureReservedIP –ReservedIPName “MyReservedIP” –Label "ReservedLabel" –Location "North Europe"


Thrustratingly you can't assign the reserved IP address to an existing cloud service - which means we have to delete the virtual machine (retaining the disks!) and then re-create it with the following command - making sure we specify the old VM disk:

New-AzureVMConfig -Name <vm-name> -InstanceSize Medium -DiskName <exiting-disk-name> | Add-AzureEndpoint -Name "Remote Desktop" -Protocol "tcp" -PublicPort 3389 -LocalPort 3389 | Set-AzureSubnet <subnet-name> | New-AzureVM -ServiceName <cloud-service-name> -ReservedIPName <reserved-ip- name> -Location "North Europe" -VNetName <virtual-network-name>

or if you want to create a new VM (we use the "ImageName" oposed to "VMImageName" switch:

New-AzureQuickVM -Windows -ServiceName <cloud-service-name> -Name <vm-name> -InstanceSize Medium -VMImageName <vm-template> -AdminUsername admin -Password <password> –ReservedIPName <reseved-ip-name> –Location "North Europe"

During the process I encountered the following error:
"CurrentStorageAccountName is not accessible. Ensure the current storage account is accessible..."

This happend as I had not registered by storage account with Azure Powershell! If we do a Get-AzureSubscription - we notice that the CurrentStorageAccountName is blank! To register this we do the following:

Set-AzureSubscription -SubscriptionName "Free Trial" -CurrentStorageAccountName (Get-AzureStorageAccount).Label -PassThru

** Note: The reserved IP must reside in the same region as the vitual machine (e.g. in this case North Europe.) **

If you wish to remove a reserved IP:
Remove-AzureReservedIP -ReservedIPName "MY-IP-NAME"


Post a Comment