Create an Azure VM with a Static IP

Author by Shannon Fritz

Since the release of Azure IaaS we’ve been unable to use Static IP addresses on Virtual Machines.  This is no longer the case!  A new PowerShell cmdlet named Set-AzureStaticVNetIP let’s you assign an address to your VM Configuration when you create a new Virtual Machine.  So how do you actually set an Azure Static IP? Configure a Static Internal IP Address (DIP) for a VM I decided to write up a script that would be easy to use and modify and use for some one-off builds of VM’s in Azure IaaS.  To that effect, I am making a few assumptions:

  1. You already have an Azure Account
  2. You’ve already created a Virtual Network in Azure
  3. You’ve already created a Storage Account in Azure

If you haven’t done those things yet then you get that taken care of by following my earlier post about Getting Started with Site-to-Azure VPN Setup and follow it until you get to the part about building a Virtual Machine.  Next, from the computer you want to run this script, install the latest version of Azure PowerShell (v0.7.3.1 or newer).  The Web Installer will setup all of it’s prerequisite’s for you. Next, download the script and edit it.  I've included many comments to help you determine the correct values for your deployment. Finally, launch Azure PowerShell then run the “Add-AzureAccount” command which will prompt you for your Azure Account Credentials (Note: When you close the Azure PowerShell window your login session will also close).  After you’ve logged in, you can run this script to create your VM. image Download the script: Make-AzureVM.ps1 When it’s done you’ll see your fresh new VM running and ready in the Azure management portal.  You can edit the script and create other VMs, decide if you want a Static or Dynamic IP, even join a Windows AD Domain or add additional VHD's if you'd like. image I wrote this script with the intent to be used as a way to pretty quickly deploy one server at a time, and to be a starting point for other scripts.  It is intended to be run manually from the command line, but if you set up Certificate authentication you could use this script with some automation engine like Orchestrator or SMA. About Static IP's in Azure While the command is actually called Set-AzureStaticVNetIP, what it's really doing is setting a DHCP Reservation for your Virtual Machine.  This means inside your VM, the network adapter is still configured as a DHCP client, but it will always be given the same IP regardless of the "boot order" of other VMs on the network and even if you Shutdown / Deallocate the VM to stop getting charged for running it. So is it literally a static IP?  No, but this should do the trick for DC's, ADFS servers and other VMs that you really don't want the IP to change.  And you won't need to pull any stunts with tiny subnets anymore! N'joy!


Shannon Fritz

Infrastructure Architect & Server Team Lead