Cloud Computing

How to Easily Assign a Static IP Address in Microsoft Azure

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.

Sponsored Content

Passwords Haven’t Disappeared Yet

123456. Qwerty. Iloveyou. No, these are not exercises for people who are brand new to typing. Shockingly, they are among the most common passwords that end users choose in 2021. Research has found that the average business user must manually type out, or copy/paste, the credentials to 154 websites per month. We repeatedly got one question that surprised us: “Why would I ever trust a third party with control of my network?

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 and press Enter, replacing CONTOSO with the name of your virtual network and 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.
IP address in Microsoft Azure
Check if an IP address is available in Azure.
  • Let’s assign the 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 | 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.

Related Topics:


Don't have a login but want to join the conversation? Sign up for a Petri Account

Comments (0)

Leave a Reply

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.
Don't leave your business open to attack! Come learn how to protect your AD in this FREE masterclass!REGISTER NOW - Thursday, December 2, 2021 @ 1 pm ET

Active Directory (AD) is leveraged by over 90% of enterprises worldwide as the authentication and authorization hub of their IT infrastructure—but its inherent complexity leaves it prone to misconfigurations that can allow attackers to slip into your network and wreak havoc. 

Join this session with Microsoft MVP and MCT Sander Berkouwer, who will explore:

  • Whether you should upgrade your domain controllers to Windows Server
    2019 and beyond
  • Achieving mission impossible: updating DCs within 48 hours
  • How to disable legacy protocols and outdated compatibility options in
    Active Directory

Sponsored by: