Configure private IP addresses for a virtual machine using the Azure portal
Your IaaS virtual machines (VMs) and PaaS role instances in a virtual network automatically receive a private IP address from a range that you specify, based on the subnet they are connected to. That address is retained by the VMs and role instances, until they are decommissioned. You decommission a VM or role instance by stopping it from PowerShell, the Azure CLI, or the Azure portal. In those cases, once the VM or role instance starts again, it will receive an available IP address from the Azure infrastructure, which might not be the same it previously had. If you shut down the VM or role instance from the guest operating system, it retains the IP address it had.
In certain cases, you want a VM or role instance to have a static IP address, for example, if your VM is going to run DNS or will be a domain controller. You can do so by setting a static private IP address.
Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure resource. You can view the documentation for different tools by clicking the tabs at the top of this article.
This article covers the Resource Manager deployment model. You can also manage static private IP address in the classic deployment model.
To better illustrate how to configure a static IP address for a VM, this document will use the scenario below.
In this scenario you will create a VM named DNS01 in the FrontEnd subnet, and set it to use a static IP address of 192.168.1.101.
The following sample steps expect a simple environment already created. If you want to run the steps as they are displayed in this document, first build the test environment described in create a vnet.
How to create a VM for testing static private IP addresses
You cannot set a static private IP address during the creation of a VM in the Resource Manager deployment mode by using the Azure portal. You must create the VM first, then set its private IP to be static.
To create a VM named DNS01 in the FrontEnd subnet of a VNet named TestVNet, follow these steps:
- From a browser, navigate to http://portal.azure.com and, if necessary, sign in with your Azure account.
Click Create a resource > Compute > Windows Server 2012 R2 Datacenter, notice that the Select a deployment model list already shows Resource Manager, and then click Create, as seen in the following figure.
In the Basics pane, enter the name of the VM to create (DNS01 in the scenario), the local administrator account, and password, as seen in the following figure.
Make sure the Location selected is Central US, then click Select existing under Resource group, then click Resource group again, then click TestRG, and then click OK.
In the Choose a size pane, select A1 Standard, and then click Select.
In the Settings pane, be sure the properties are set with the following values, and then click OK.
-Storage account: vnetstorage
- Network: TestVNet
In the Summary pane, click OK. Notice the following tile displayed in your dashboard.
How to retrieve static private IP address information for a VM
To view the static private IP address information for the VM created with the steps above, execute the following steps.
From the Azure portal, click BROWSE ALL > Virtual machines > DNS01 > All settings > Network interfaces and then click on the only network interface listed.
In the Network interface pane, click All settings > IP addresses and notice the Assignment and IP address values.
How to add a static private IP address to an existing VM
To add a static private IP address to the VM created using the steps above, follow these steps:
- From the IP addresses pane shown above, click Static under Assignment.
Type 192.168.1.101 for IP address, and then click Save.
If after clicking Save, you notice that the assignment is still set to Dynamic, it means the IP address you typed is already in use. Try a different IP address.
How to remove a static private IP address from a VM
To remove the static private IP address from the VM created above, complete the following step:
From the IP addresses pane shown above, click Dynamic under Assignment, and then click Save.