แก้ไข

แชร์ผ่าน


Create a virtual machine with a static private IP address using the Azure portal

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 VM

Use the following steps to create a VM, and its virtual network and subnet:

  1. Sign in to the Azure portal.

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

  3. Select Create > Azure virtual machine.

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

    • Subscription: Keep the default or select a different subscription.
    • Resource group: Select Create new, and then name the group myResourceGroup.
    • Virtual machine name: Enter myVM.
    • Region: Select (US) East US.
    • Availability options: Select No infrastructure redundancy required.
    • Image: Select Windows Server 2019 Datacenter - x64 Gen2.
    • Size: Accept the default, or drop down and select a size.
    • Username, Password, and Confirm password: Enter an admin username and password for the VM.
    • Public inbound ports: Select Allow selected ports.
    • Select inbound ports: Select RDP (3389).

    Screenshot that shows the Basic tab of the Create a virtual machine window.

    Warning

    In this example, you open port 3389 to enable remote access to the Windows Server VM from the internet. However, opening port 3389 to the internet is not recommended to manage production workloads. For information about secure access to Azure VMs, see What is Azure Bastion?.

  5. Select the Networking tab at the top of the page.

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

    • Virtual network: Accept the default network name.
    • Subnet: Select default if not already selected.
    • Public IP: Accept the default public IP configuration.
    • Public inbound ports: Select Allow selected ports.
    • Select inbound ports: Select RDP (3389).
  7. Select Review + create. 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 backend 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 one of the following events happens:

  • A public IP address is assigned to the VM.
  • The VM is placed in the backend pool of a standard load balancer, with or without outbound rules.
  • An Azure NAT Gateway resource is assigned to the subnet of the VM.

VMs that you create by using virtual machine scale sets in flexible orchestration mode don't have default outbound access.

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 procedure, you change the private IP address from dynamic to static for the VM you 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, under Settings, select Networking.

  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. On the Network interface page, under Settings, select IP configurations.

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

    Screenshot of select ip configuration.

  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.

    Screenshot of select static assignment.

Warning

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 you're finished, 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