X
Closing this message and/or accessing our website tells us you are happy to receive all cookies on the ClearPeople website.
However, if you would like to, you can change your cookies settings at any time.
Recently we had the need to change the public IP of some Azure VMs to be static instead of dynamic to prevent them from changing when the VM is shut down or deallocated. It was interesting to see that it is possible to reserve the same IP the VMs are currently using which prevent us from having to update references to those IPs. And also it is possible to do so without any downtime as the VM doesn't need to be restarted. PowerShell is the only way available at the time being to get this done.

How to do it

1. The steps to reserve the VM’s IP are as follows:

Step 1: Get the settings required by PowerShell to connect to the Azure subscription. 

Step 2: With your favourite browser, navigate to https://manage.windowsazure.com, log in and select the subscription where the target VM is. 

Step 3: Run the following PowerShell command which will download a file with the settings required by PowerShell to connect to the same subscription.          

Get-AzurePublishSettingsFile

Step 4: Save the previously downloaded file in a safe location.

 

Connect PowerShell to the target Azure subscription

2. Run the following two PowerShell statements after setting the path to the Publishing Settings file (downloaded in the previous step) and the Azure SubscriptionName.

Import-AzurePublishSettingsFile "<Path to Publish Settings file>"
Select-AzureSubscription -SubscriptionName "<Subscription Name>"



3. [Optional] We can check the currently reserved IPs:

Get-AzureReservedIP

We can also save this information to a file for tracking purposes.

Get-AzureReservedIP >> "C:\ReservedIPs.old.details.txt"


4. Reserve the IP that is currently assigned to the VM:

Run the following command after setting the right values to its parameters.

New-AzureReservedIP –ReservedIPName <IP Name> –Location "<Region>" -ServiceName <Cloud Service Name>


ReservedIPName: Name to be used to identify the reserved IP. • Location: Name of the Azure Region where the VM is and where the IP will be reserved.
ServiceName: Name of the Azure Cloud Service associated to the VM.


5. [Optional] We can check again the currently reserved IPs where the new IP should be:

Get-AzureReservedIP

We can also save this information to a file for tracking purposes.

Get-AzureReservedIP >> "C:\ReservedIPs.new.details.txt"


How to double-check the VM has a reserved IP

The above procedure not only reserves the IP but also associates it to the VM. We can confirm it with the following steps:
Step 1: With your favourite browser navigate to the new Azure Management Portal https://portal.azure.com/
Step 2: Select the subscription where the target VM is.
Step 3: Go to “Virtual Machines (classic)”.
Step 4: Select (click on) the target VM which IP has just been reserved.
Step 5: On the Settings panel click on “IP addresses”.
Step 6: On the “IP addresses” panel we can check whether the IP is reserved and associated to the VM:


Additional information

https://azure.microsoft.com/en-gb/documentation/articles/virtual-networks-reserved-public-ip/

Author bio

Benjamin Moles
Benjamin Moles
.NET Developer
I'm a passionate .NET and SQL developer. I've worked with a broad variety of technologies and I am currently contributing to the success of ClearPeople's Sitecore projects. Beside IT stuff, I love to spend time with family and play with remote-controlled helicopters.

Comments


comments powered by Disqus

Related Articles

Sign up to our Newsletter

Every now and then, we'd like to send you information that delivers, develops and promotes our products and services that are relevant to you. Submitting your details tells us that you're OK with this and you also agree to our Privacy & Cookies policy. You can, of course, opt out of these communications at any time.