Q: How do I set a static IP address for a virtual machine (VM) in Windows Azure IaaS?

A: Prior to Windows Azure PowerShell, it wasn't possible to give a VM in a virtual network subnet a static IP address that persisted even if the VM was deprovisioned (shutdown from the portal) and therefore no long billed for.

The only option was to create different virtual subnets for different groups of VMs to try and control the IP address the VM would be given from Windows Azure.

RELATED: Video: Using Static IP Addresses in Azure

The Virtual Network static IP feature is now available through PowerShell ( and later), which is available at the Window Azure website. This enables a static IP to be assigned to a VM that will persist with the VM, even if it's deprovisioned. The VM must be within a virtual network to have a static IP address configured. There are four cmdlets used:

  • Set-AzureStaticVNetIP - Sets a static IP address, e.g. Set-AzureStaticVNetIP -VM <VM> -IPAddress <IP address string>
  • Get-AzureStaticVNetIP - Gets the static IP address of the passed VM
  • Remove-AzureStaticVNetIP - Removes the static IP address of the passed VM
  • Test-AzureStaticVNetIP - Checks to see if a certain static IP address is available from a virtual network, e.g., Test-AzureStaticVNetIP -VNetName <network name> -IPAddress <IP address string>

As a best practice, don't mix VMs using static IP addresses with VMs using DHCP within a subnet. Instead, create dedicated subnets within the virtual network that will be used for VMs using static IP addresses. Below is an example of these cmdlets in action in my environment, but this won't actually take effect until the Windows Azure region you're using has implemented this functionality:

  1. PS C:\> Test-AzureStaticVNetIP -VNetName SavTechNet115 -IPAddress
  3. IsAvailable          : False
  4. AvailableAddresses   : {,,,}
  5. OperationDescription : Test-AzureStaticVNetIP
  6. OperationId          : c6f70cc4-bf36-7907-9c7e-bc1c2e925cbb
  7. OperationStatus      : Succeeded
  10. PS C:\> Test-AzureStaticVNetIP -VNetName SavTechNet115 -IPAddress
  13. IsAvailable          : True
  14. AvailableAddresses   : {}
  15. OperationDescription : Test-AzureStaticVNetIP
  16. OperationId          : 30d13740-42a3-724a-8dc8-0f418a6a6af9
  17. OperationStatus      : Succeeded
  20. PS C:\> $staticVM = Get-AzureVM -ServiceName savnetazu115 -Name TestStaticVM
  22. PS C:\> Set-AzureStaticVNetIP -VM $staticVM -IPAddress | Update-AzureVM
  24. PS C:\> Get-AzureStaticVNetIP -VM $staticVM
  26. IPAddress                                                                                                                                                                                    
  27. ---------                                                                                                                                                                                    

I walk through this whole process in my video Using Static IP Addresses in Azure