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.

Prerequisites

Create virtual machine

Use the following steps to create a virtual machine, virtual network, and subnet.

  1. Sign in to the Azure portal.

  2. In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.

  3. Select + Create, then + Virtual machine in Virtual machines.

  4. 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 (US) East US 2.
    Availability options Select No infrastructure redundancy required.
    Image Select Windows Server 2019 Datacenter - Gen2.
    Azure Spot instance Leave unchecked.
    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)

    Screenshot of create virtual machine.

    Warning

    Portal 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?

  5. Select the Networking tab, or select Next: Disks, then Next: Networking.

  6. 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)
  7. Select Review + create.

  8. Review the settings, and then select Create.

Note

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.

For more information, see Default outbound access in Azure.

The default outbound access IP is disabled when either a public IP address is assigned to the VM or the VM is placed in the back-end pool of a standard load balancer, with or without outbound rules. If an Azure Virtual Network network address translation (NAT) gateway resource is assigned to the subnet of the virtual machine, the default outbound access IP is disabled.

VMs that are created by virtual machine scale sets in flexible orchestration mode don't have default outbound access.

For more information about outbound connections in Azure, see 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.

  1. In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.

  2. In Virtual machines, select myVM.

  3. Select Networking in Settings in myVM.

  4. In Networking, select the name of the network interface next to Network interface. In this example, the name of the NIC is myvm472.

    Screenshot of select network interface.

  5. In the network interface properties, select IP configurations in Settings.

  6. Select ipconfig1 in the IP configurations page.

    Screenshot of select ip configuration.

  7. Select Static in Assignment. Select Save.

    Screenshot of select static assignment.

    Note

    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.

To change the IP address back to dynamic set the assignment for your private IP address to Dynamic, and then select Save.

Warning

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:

  1. Enter myResourceGroup in the Search box at the top of the portal. When you see myResourceGroup in the search results, select it.

  2. Select Delete resource group.

  3. Enter myResourceGroup for TYPE THE RESOURCE GROUP NAME: and select Delete.

Next steps