Configure a private IP address for a VM using the Azure portal
A virtual machine (VM) is automatically assigned a private IP address from a range that you specify, based on the subnet in which the VM is deployed. The VM retains the address until the VM is deleted. Azure dynamically assigns the next available private IP address from the subnet you create a VM in. If you want a specific IP address from the subnet assigned to the VM, assign a static IP address.
To better illustrate how to configure a static IP address for a VM, this document uses this scenario:
In this scenario, you create a VM named DNS01 in the FrontEnd subnet, and then set it to use a static IP address of 192.168.1.101.
The following sample steps expect a simple environment to already be created. If you want to run the steps as they're displayed in this document, first create a virtual network. However, in step 3, use these values instead:
|Resource group||TestRG (if necessary, select Create new to create it)|
|Subnet - Name||FrontEnd|
|Subnet - Address range||192.168.1.0/24|
Create a VM for testing static private IP addresses
When you create a VM in Resource Manager deployment mode, you can't set a static private IP address using the Azure portal. Instead, you create the VM first. Then you can set its private IP to be static.
To create a VM named DNS01 in the FrontEnd subnet of a virtual network named TestVNet, follow these steps:
From the Azure portal menu, select Create a resource.
Enter Windows Server 2019 Datacenter in filter box and select the Enter key, then select the Windows Server 2019 Datacenter in search result.
In Basics, specify values for items as described in the following table. Then select Next : Disks and then Next : Networking.
Item Value Subscription Your current subscription Resource group TestRG (select from dropdown list) Virtual machine name DNS01 Region China East Image Windows Server 2019 Datacenter Size VM Size of B1ls, Offering of Standard Username The user name of your administrator account Password The password for your administrator account's user name Confirm password The password again
In Networking, specify values for items as described in the following table, and then select Next.
Item Value Virtual network TestVNet Subnet FrontEnd
In Management, under Diagnostics storage account, choose vnetstorage. If that storage account doesn't appear in the list, select Create new, specify a Name of vnetstorage, and select OK. Finally, select Review + create.
In Review + create, review the overview information, and then select Create.
The following message appears once the VM is created.
Retrieve private IP address information for a VM
To view the private IP address information for your new VM:
Go to the Azure portal to find your VM. Search for and select Virtual machines.
Select the name of your new VM (DNS01).
Choose Networking, and select the sole network interface listed.
Choose IP configurations, and select the IP configuration listed in the table.
In Private IP address settings, under the TestVNet/FrontEnd virtual network/subnet, note the Assignment value (Dynamic or Static) and the IP address.
Add a static private IP address to an existing VM
To add a static private IP address to your new VM:
In the IP configuration page, set the assignment for your private IP address to Static.
Change your private IP address to 192.168.1.101, and then select Save.
If you notice after selecting Save that the assignment is still set to Dynamic, the IP address you typed is already in use. Try another IP address.
Remove a static private IP address from a VM
To remove the static private IP address from your VM:
In the IP configuration page, set the assignment for your private IP address to Dynamic, and then select Save.
Set IP addresses within the operating system
From within the operating system of a VM, you shouldn't statically assign the private IP that's assigned to the Azure VM. Only do static assignment of a private IP when it's necessary, such as when assigning many IP addresses to VMs. If you manually set the private IP address within the operating system, make sure it matches the private IP address assigned to the Azure network interface. Otherwise, you can lose connectivity to the VM. Learn more about private IP address settings.
Also, you should never manually assign the public IP address assigned to an Azure virtual machine within the virtual machine's operating system.
Learn about managing IP address settings.