Create a virtual machine with a static private IP address using the Azure portal
A virtual machine (VM) is automatically assigned a private IP address from a range that you specify. This range is based on the subnet in which the VM is deployed. The VM keeps the address until the VM is deleted. Azure dynamically assigns the next available private IP address from the subnet you create a VM in. Assign a static IP address to the VM if you want a specific IP address in the subnet.
- An Azure account with an active subscription. Create a trial subscription.
Create virtual machine
Use the following steps to create a virtual machine, virtual network, and subnet.
Sign in to the Azure portal.
In the search box at the top of the portal, enter Windows Server 2019 Datacenter (Gen2). Select Windows Server 2019 Datacenter (Gen2) in the search results.
In Create a virtual machine, enter or select the following information:
Setting Value Project details Subscription Select your subscription. Resource group Select Create new. Enter myResourceGroup in Name. Select OK. Instance details Virtual machine name Enter myVM. Region Select (Asia Pacific) China East 2. Availability options Select No infrastructure redundancy required. Image Select Windows Server 2019 Datacenter - Gen2. Size Select a size. Administrator account Username Enter a username. Password Enter a password. Confirm password Reenter password. Public inbound ports Select Allow selected ports. Select inbound ports Select RDP (3389)
Port 3389 is selected to enable remote access to the Windows Server virtual machine from the internet. Opening port 3389 to the internet is not recommended to manage production workloads. For secure access to Azure virtual machines, see What is Azure Bastion?
Select the Networking tab, or select Next: Disks, then Next: Networking.
In the Networking tab, select or enter:
Setting Value Network interface Virtual network Accept the default network name. Subnet Accept the default subnet configuration. Public IP Accept the default public IP configuration. NIC network security group Select Basic Public inbound ports Select Allow selected ports. Select inbound ports Select RDP (3389)
Select Review + create.
Review the settings, and then select Create.
Azure provides a default outbound access IP for VMs that either aren't assigned a public IP address or are in the back-end pool of an internal basic Azure load balancer. The default outbound access IP mechanism provides an outbound IP address that isn't configurable.
The default outbound access IP is disabled when a public IP address is assigned to the VM, the VM is placed in the back-end pool of a standard load balancer, with or without outbound rules, or if an Azure Virtual Network NAT gateway resource is assigned to the subnet of the VM.
For more information about outbound connections in Azure, see Default outbound access in Azure and Use source network address translation (SNAT) for outbound connections.
Change private IP address to static
In this section, you'll change the private IP address from dynamic to static for the virtual machine you created previously.
In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.
In Virtual machines, select myVM.
Select Networking in Settings in myVM.
In Networking, select the name of the network interface next to Network interface. In this example, the name of the NIC is myvm472.
In the network interface properties, select IP configurations in Settings.
Select ipconfig1 in the IP configurations page.
Select Static in Assignment. Change the private IP address if you want a different one, and then select Save.
If you change the private IP address, the VM associated with the network interface will be restarted to utilize the new IP address.
To change the IP address back to dynamic set the assignment for your private IP address to Dynamic, and then select Save.
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.
Clean up resources
When no longer needed, delete the resource group and all of the resources it contains:
Enter myResourceGroup in the Search box at the top of the portal. When you see myResourceGroup in the search results, select it.
Select Delete resource group.
Enter myResourceGroup for TYPE THE RESOURCE GROUP NAME: and select Delete.
Learn more about static public IP addresses.
Learn more about public IP addresses in Azure.
Learn more about all public IP address settings.
Learn more about private IP addresses and assigning a static private IP address to an Azure virtual machine.