Skip to main content

AZURE: Creating new VM with static IP address

This case took me whole day. It wasn't easy because of Azure service is still evolving. Commands and dependencies between them are changing, but documentation do not. Some websites and blogs steered me on the course where to find the solution, but I have not found final, working version.
Here are the links:


So if you are here, you are looking for how to have VM with static IP or you are struggling with problems with creating VM.

First thing you must know is that Azure gives your cloud service virtual IP address (VIP). So, even if you are set local network IP for VM's, then still you are using dynamic VIP.
If you will stop your virtual machines, then VIP is freed and during next start you will get different IP.
To solve this you need to create static VIP.

As Microsoft says, you must consider following:

  • Reserved IP can only be used for VMs and cloud service web/worker roles.

  • You must reserve the IP address first, before deploying.

  • At this time, you can’t go back and apply a reservation to something that’s already been deployed.
  • Reserved IP is supported only for Regional VNets. It is not supported for VNets that are associated with affinity groups. For more information about associating a VNet with a region or an affinity group, see About Regional VNets and Affinity Groups for Virtual Network.

To set static IP address for VIP, do the following:


New-AzureReservedIP -ReservedIPName "reservedIP" -Label "reserverIP" -Location "WestEurope"

As you already have static IP for your service, you can now create VM's with local, static IP addresses, which will not change even after switching machines of.

I have created VM with static IP address using image snapshot of VM from configured machine. You can use either an image prepared by Microsoft and listed as a Quick in the Gallery (short description here) or you can use an image which you could have prepared earlier.

First, test the desired IP address if it can be used:

Test-AzureStaticVNetIP -VNetName "VNetName" -IPAddress 10.0.1.5



As you can see, I've chosen IP address which is already in use (IsAvaiable:False), but I can use 10.0.1.6, .7, .8, etc 


Now, the cmdlet that works for me. I've made it working after many tests, so this is it:

New-AzureVMConfig -Name "DCVM" -ImageName "DCVM_image" -InstanceSize "Basic_A2" -MediaLocation "https://dysk.blob.core.windows.net/data" | Add-AzureProvisioningConfig -Windows -AdminUsername "admini123" -Password "SomePass2#@"|Set-AzureSubnet -SubnetNames "subnet-1" | Set-AzureStaticVNetIP -IPAddress 10.0.1.6 | New-AzureVM
 -ServiceName "myazurservicename" -VNetName "virtualnetworkname" -ReservedIPName "reservedIP"

Similar commands to create VM from gallery's image:

New-AzureVMConfig -Name "DCWEP" -ImageName "3a50f22b388a4ff7ab41029918570fa6__Windows-Server-2012-Essentials-20140715-enus" -InstanceSize "Basic_A2" | Add-AzureProvisioningConfig -Windows -AdminUsername "admini123" -Password "SomePass2#@"|Set-AzureSubnet -SubnetNames "subnet-1" | Set-AzureStaticVNetIP -IPAddress 10.0.1.7 | New-AzureVM  -ServiceName "myservicename"

Remember to use your own parameters for variables (in bold).