Edit

Share via


Create a virtual machine with a static private IP address

When you create a virtual machine (VM), it's automatically assigned a private IP address from a range that you specify. This IP address is based on the subnet in which the VM is deployed, and the VM keeps this 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 to assign a specific IP address in this subnet for your VM, use a static IP address.

Prerequisites

Create a resource group and a virtual machine

Create a resource group

  1. Sign in to the Azure portal.

  2. In the portal, search for and select Resource groups.

  3. Select + Create.

  4. On the Basics tab, enter or select the following values:

    Setting Value
    Subscription Select your subscription
    Resource group Enter myResourceGroup
    Region Select (US) East US
  5. Select Review + create, and then select Create.

Create a virtual network

  1. In the portal, search for and select Virtual networks.

  2. Select + Create.

  3. On the Basics tab of Create virtual network, enter or select the following values:

    Setting Value
    Subscription Select your subscription
    Resource group Select myResourceGroup
    Virtual network name Enter myVNet
    Region Select (US) East US
  4. Select Review + create, and then select Create.

Create a virtual machine

  1. In the portal, search for and select Virtual machines.

  2. Select Create > Azure virtual machine.

  3. On the Basics tab of the Create a virtual machine screen, enter or select the following values:

    Setting Value
    Subscription Select your subscription
    Resource group Select myResourceGroup
    Virtual machine name Enter myVM
    Region Select (US) East US 2
    Availability options Select No infrastructure redundancy required
    Security type Select Standard
    Image Select Ubuntu Server 22.04 LTS - x64 Gen2
    Size Accept the default, or drop down and select a size
    Authentication type Select SSH public key
    Username Enter azureuser
    SSH public key source Select Generate new key pair
    Key pair name Enter mySSHKey
    Public inbound ports Select None
  4. Select the Networking tab at the top of the page.

  5. On the Networking page, enter or select the following values:

    • Virtual network: Select myVNet.
    • Subnet: Select default if not already selected.
    • Public IP: Select None.
  6. Select Review + create. Review the settings, and then select Create.

Note

The virtual machine is created without a public IP address and with no public inbound ports. To connect to the virtual machine, use Azure Bastion. For more information, see Quickstart: Deploy Azure Bastion with default settings.

Change private IP address to static

In the following steps, you change the private IP address static for the VM created previously:

  1. In the portal, search for and select Virtual machines.

  2. In Virtual machines, select myVM from the list.

  3. On the myVM page, select Network settings under Networking.

  4. On the Network settings page, select the name of the network interface next to Network interface.

  5. On the Network interface page, under Settings, select IP configurations.

  6. In IP configurations, select ipconfig1 in the list.

  7. Under Assignment, select Static. Change the private IP address if you want a different one, and then select Save.

Warning

If you change the private IP address, the VM associated with the network interface will be restarted to utilize the new IP address.

From within the operating system of a VM, avoid associating a static private IP address on an Azure VM. Only assign a static 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. For more information, see private IP address settings.

Clean up resources

When all the resources are no longer need, delete the resource group and all of the resources it contains:

  1. In the portal, search for and select myResourceGroup.

  2. From the myResourceGroup screen, select Delete resource group.

  3. Enter myResourceGroup for Enter resource group name to confirm deletion, and then select Delete.

Next steps