Microsoft is constantly improving its Azure cloud computing platform, and in spring this year a series of updates to Microsoft Azure PowerShell cmdlets made it much easier to assign VMs with a static IP address.
Prior to the spring round of updates to the Azure platform, the only way to assign a static IP address to a VM was to create the VM entirely using PowerShell. Now it’s possible to create a VM in the management portal and then configure a static IP address using PowerShell. In today’s Ask an Admin, I’ll show you an easy way to assign a static IP address in Microsoft Azure.
Assigning a Static IP Address: Preparation
Start by creating a new VM using the Azure management portal. For more details on how to complete this task, see “Deploy Windows Server 2012 in an Azure Virtual Machine” on Petri IT Knowledgebase. You will also need to install the latest Windows Azure PowerShell cmdlets on your management workstation. The easiest way to do this is to download and install the Web Platform Installer. To set up a secure connection to your Azure subscription, see “Setup Windows Azure PowerShell Management.”
You will also need to have a virtual network already created in order to assign an IP address from its DHCP pool. For more information, see “Setup a Virtual Network in Windows Azure.” In this article, I created a couple of subnets specifically for servers that needed static IP addresses in a lab environment. This was to avoid having to create VMs using PowerShell. Now that it’s much easier to assign static IP addresses, you can create a virtual network with just one subnet and assign static IP addresses using the method below.
Use PowerShell to Assign a Static IP Address
Now we are ready to use PowerShell to assign a static IP address. The instructions below are for Windows 8 or later.
- Switch to the Start screen, type powershell and press CTRL+SHIFT+ENTER. Enter administrator credentials or give consent if prompted.
- In the PowerShell console, type Set-AzureSubscription “Pay-As-You-Go” -CurrentStorageAccount portalvhdsxgwgzn2ml54p5 and press Enter, replacing Pay-As-You-Go and portalvhdsxgwgzn2ml54p5 with the correct information for your subscription, which can be found in the Azure management portal.
- Now check if the IP address we want to assign is available. Type Test-AzureStaticVnetIP -VNetName CONTOSO -IPAddress 10.0.0.6 and press Enter, replacing CONTOSO with the name of your virtual network and 10.0.0.6 with the IP address you want to check is free. If the address is available to be assigned, the IsAvailable variable in the cmdlet results will be True.
- Let’s assign the 10.0.0.6 address to a VM. Type $staticIP = Get-AzureVM -ServiceName CONTOSODC1 -Name CONTOSODC1 and press Enter. Replace the values in the –ServiceName and –Name parameters with the correct information for the VM you want to modify. This command defines the $staticIP variable with the correct information about our VM.
- Type Set-AzureStaticVNetIP -VM $staticIP -IPAddress 10.0.0.6 | Update-AzureVM and press Enter. The command may take a few minutes to complete. If the VM is currently running, you will need to restart it for it to automatically be assigned the new address.
- Finally, we can confirm the VMs configuration by typing Get-AzureStaticVNetIP -VM $staticIP and pressing Enter.