Wednesday, April 15, 2015

How to assign reserved IP to existing Virtual Machine in Microsoft Azure Cloud

I don't know why Microsoft cannot offer a single click tool to add a permanent static IP to any Azure resource. Moreover I don't understand why it is not possible to assign a reserved IP address to an existing Virtual Machine :(

The only way (as of April 2015) to assign a permanent public IP address (reserved IP) to Virtual Machine in Microsoft Azure Cloud is the following:

  1. Stop Virtual Machine
  2. Make captured image with a custom name ("image-of-virtual-machine" for example)
  3. Manually write out all Endpoints (insane!)
  4. Delete VM and associated Cloud Service
  5. Create Reserved IP using Azure PowerShell
  6. Create a new Virtual Machine from the saved disk image
  7. Set back all Endpoints manually (insane again!)

If you have finished deleting of Virtual Machine at step 4, start Microsoft Azure PowerShell. Creating of Reserved IP is easy, just a single command call:

New-AzureReservedIP -ReservedIPName "reserved-ip-address-for-your-vm" -Label "SomeTextHere" -Location "North Europe"

To verify that Reserved IP was successfully created, call:


We've got Reserved IP, so it's time to create a new "old" Virtual Machine.

First of all call this command in Microsoft Azure PowerShell:


You'll get something like that:

SubscriptionId : 123456-e123-1234-a123-1234567890
SubscriptionName : BizSpark
Environment : AzureCloud
SupportedModes : AzureServiceManagement,AzureResourceManager
DefaultAccount :
Accounts : { }
IsDefault : True
IsCurrent : True
CurrentStorageAccountName :
TenantId : 00000000-0000-0000-0000-000000000000

If CurrentStorageAccountName is empty set it to the value you can find in Azure Management -> Storage.

Set-AzureSubscription -CurrentStorageAccountName "get_id_from_web_panel_something_like_portal23423ns43" -SubscriptionName "BizSpark"

Otherwise you've got strange errors on next steps, for example:

New-AzureVMConfig : Must specify MediaLocation or set a current storage account using Set-AzureSubscription.

Now we can create a new virtual machine from the saved image with reserved ip address. Lots of tutorials offer to call the following command (don't do it):

New-AzureVMConfig -Name "your-virtual-machine-name" -InstanceSize "Small" -ImageName "image-of-virtual-machine" | New-AzureVM -ServiceName "could-be-same-as-vm-name" -ReservedIPName "reserved-ip-address-for-your-vm" -Location "North Europe"

But in 99% you'll get error:

New-AzureVM : BadRequest: A ProvisioningConfigurationSet was not found in the ConfigurationSet collection of the virtual machine with name your-virtual-machine-name. When creating a virtual machine from an image, ProvisioningConfiguration Set must be specified.

So add Add-AzureProvisioningConfig section into the command (call this):

New-AzureVMConfig -Name "your-virtual-machine-name" -InstanceSize "Small" -ImageName "image-of-virtual-machine" | Add-AzureProvisioningConfig -Linux | New-AzureVM -ServiceName "could-be-same-as-vm-name" -ReservedIPName "reserved-ip-address-for-your-vm" -Location "North Europe"

BTW, don't set any LinuxUser/AdminUsername or Password if you are creating Virtual Machine from disk image, otherwise you've got an error:

New-AzureVM : BadRequest: No Configuration Set should be specified while using a VMImage with a specialized OS Disk Configuration.

Almost done, you'll get a new virtual machine with the permanent public IP running in a few minutes.

Don't forget to add all endpoints! I prefer to do that using web interface. Also update internal IP address for all services on the Virtual Machine. New VM has a different IP address, either public or internal one.

Hope that helps and there were no problems on the Azure side while you are following these instructions :)

Why is it so hard?!

No comments: