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

What is “Inside Microsoft Teams”?

“Inside Microsoft Teams” is a webcast series, now in Season 4 for IT pros hosted by Microsoft Product Manager, Stephen Rose. Stephen & his guests comprised of customers, partners, and real-world experts share best practices of planning, deploying, adopting, managing, and securing Teams. You can watch any episode at your convenience, find resources, blogs, reviews of accessories certified for Teams, bonus clips, and information regarding upcoming live broadcasts. Our next episode, “Polaris Inc., and Microsoft Teams- Reinventing how we work and play” will be airing on Oct. 28th from 10-11am PST.

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.
External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by: