PT-BR: Como este parece ser um problema recorrente da comunidade, resolvi escrever este artigo em inglês para que possa atingir um número maior de pessoas.
EN-US: As this seems to be a recurring problem in the community, I’ve decided to write this article in English to reach a larger audience.
Is it possible to assign a reserved ip address to an existing VM or Cloud service?
No! At this moment you can’t. You have to redeploy your virtual machine in order to use a reserved ip. I’ll update this article in case Microsoft adds this functionality in the future.
What can I do? I don’t want to lose all the work I’ve done on this VM.
Simply redeploy your VMs by deleting and keeping the VHD or by capturing an Image of it before deleting. I will explain how to redeploy your VM using an Image.
Take note of the endpoints:
First things first. Make sure to take notes of all the current endpoints for this virtual machine because we are going to lose this information after deletion. From Azure Portal, navigate to Virtual Machines -> Endpoints tab. In my case, I only have 1: The default remote desktop port.
Capturing an Image:
Now go back to Instances, select the VM and click Shutdown on bottom menu bar. Wait for a complete shutdown (deallocation) and hit the capture button.
As you can see, there’s a clear warning regarding sysprep (or deprovision of waagent for Linux VMs). In this case, we won’t be creating several VMs using the same Image, we just want to redeploy the exact same machine to later delete the image file, that way there’s no need to sysprep or to deprovision the agent. It doesn’t mean you couldn’t. Best practice says you should do it actually. The good thing about syspreping a Windows Server VM is that after generalize it will be automatically deleted.
On the “Capture the virtual machine”, type something to describe the image and hit apply.
On the images tab you should see your newly created image on the list.
Deleting the current deployment:
Best way to wipe everything at once is to delete the cloud service. Navigate to Cloud Services, select the CS associated with the specified VM and hit “Delete the cloud service and all it’s deployments”. This will delete the VM, disks and everything associated with it. Don’t worry, our Image won’t be touched.
Double check everything that will be deleted because there’s no way to restore a deleted Azure asset
In my case it will delete 1 Virtual Machine with 4 disks. Don’t worry about the additional attached disks in case you have it like me, the captured image will restore them. Well, not actually restore the old ones because they will be deleted, but the image contains a copy of all the disks and they will be redeployed as well.
Reserving an Ip Address:
Now open Azure Powershell and type the following:
New-AzureReservedIP –ReservedIPName "Demo1VIP" –Label "Demo1VIP" –Location "East US
Basically I’m reserving an Ip called “Demo1VIP” on the East US data center. Make sure the location of your reserved ip is in the same location as your captured image. You can see details about the RVIP using the command Get-AzureReservedIP:
PS C:\> Get-AzureReservedIP "Demo1VIP" ReservedIPName : Demo1VIP Address : 22.214.171.124 Id : 14c3ad9a-8f57-4c8a-869f-8dd8a55c58d2 Label : Demo1VIP Location : East US State : Created InUse : False ServiceName : DeploymentName : OperationDescription : Get-AzureReservedIP OperationId : e280cec7-9dc5-8ed3-80d8-1ee98c456918 OperationStatus : Succeeded
Redeploying the Virtual Machine:
Now we are going to pipe a few commands all at once. First we create the VM config passing the captured image as parameter, add the original endpoints (you must add at least one, you can add more later through the portal if you want) and finally create the VM with New-AzureVM command with -ReservedIPName parameter.
New-AzureVMConfig -Name "bnlf-demo" -InstanceSize "Large" –ImageName "bnlf-demo1-20150323-516698" | Add-AzureEndpoint -Name "RDP" -Protocol "tcp" -PublicPort 3386 -LocalPort 3386 | New-AzureVM -ServiceName "bnlf-demo" –ReservedIPName "Demo1VIP" -Location "East US"
OperationDescription OperationId OperationStatus -------------------- ----------- --------------- New-AzureVM 2e8c084b-0077-8551-9734-d1f2f3c3c1d2 Succeeded
That’s it. At this point you should have your VM back online using the reserved VIP address and remote desktop (or SSH) should work as expected.
 Reserved IP Address. https://msdn.microsoft.com/en-us/library/azure/dn690120.aspx
 Windows Azure Management Cmdlets. https://msdn.microsoft.com/en-us/library/azure/dn495184.aspx