Create an Azure Virtual Machine with a dual-stack network

In this article, you create a virtual machine in Azure with the Azure portal. The virtual machine is created along with the dual-stack network as part of the procedures. You choose from the Azure portal, Azure CLI, or Azure PowerShell to complete the steps in this article. When completed, the virtual machine supports IPv4 and IPv6 communication.

Prerequisites

Create a resource group and virtual network

In this section, you create a resource group and dual-stack virtual network for the virtual machine in the Azure portal.

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 (Asia) China North 3.
  5. Select Review + create, and then select Create.

Create a virtual network

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

  2. Select + Create.

  3. In the Basics tab of Create virtual network, enter or select the following information.

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select myResourceGroup.
    Instance details
    Name Enter myVNet.
    Region Select China North 3.
  4. Select the IP Addresses tab, or Next>Next.

  5. Leave the default IPv4 address space of 10.0.0.0/16. If the default is absent or different, enter an IPv4 address space of 10.0.0.0/16.

  6. Select the default subnet.

  7. On the Edit subnet page, enter myBackendSubnet in Subnet name and select Save.

  8. Select Add IPv6 address space from the dropdown menu.

  9. In IPv6 address space, edit the default address space and change its value to 2404:f800:8000:122::/63.

  10. To add an IPv6 subnet, select + Add a subnet and enter or select the following information:

    Setting Value
    Subnet
    Subnet name Enter myBackendSubnet.
    Address range Leave default of 2404:f800:8000:122::.
    Size Leave the default of /64.
  11. Select Add.

  12. Select the Review + create.

  13. Select Create.

Create public IP addresses

You create two public IP addresses in this section, IPv4 and IPv6 in the Azure portal.

Create IPv4 public IP address

  1. In the search box at the top of the portal, enter Public IP address. Select Public IP addresses in the search results.

  2. Select + Create.

  3. Enter or select the following information in Create public IP address.

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select myResourceGroup.
    Location Select China North 3.
    Availability zone Select Zone redundant.
    Instance details
    Name Enter myPublicIP-IPv4.
    IP version Select IPv4.
    SKU Leave the default of Standard.
    Tier Leave the default of Regional.
    IP address assignment
    Routing preference Leave the default of Microsoft network.
    Idle timeout (minutes) Leave the default of 4.
    DNS name label Enter myPublicIP-IPv4.
  4. Select Review + create then Create.

Create IPv6 public IP address

  1. In the search box at the top of the portal, enter Public IP address. Select Public IP addresses in the search results.

  2. Select + Create.

  3. Enter or select the following information in Create public IP address.

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select myResourceGroup.
    Location Select China North 3.
    Availability zone Select Zone redundant.
    Instance details
    Name Enter myPublicIP-IPv6.
    IP version Select IPv6.
    SKU Leave the default of Standard.
    Tier Leave the default of Regional.
    IP address assignment
    DNS name label Enter myPublicIP-IPv6.
  4. Select Review + create then Create.

Create virtual machine

In this section, you create the virtual machine and its supporting resources.

Create virtual machine

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

  2. Select + Create then Azure virtual machine.

  3. In the Basics tab, enter or select the following information.

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select myResourceGroup.
    Instance details
    Virtual machine name Enter myVM.
    Region Select China North 3.
    Availability options Select No infrastructure redundancy required.
    Security type Select Standard.
    Image Select Ubuntu Server 20.04 LTS - Gen2.
    Size Select the default size.
    Administrator account
    Authentication type Select SSH public key.
    Username Enter a username.
    SSH public key source Select Generate new key pair.
    Key pair name Enter mySSHKey.
    Inbound port rules
    Public inbound ports Select None.
  4. Select the Networking tab, or Next: Disks then Next: Networking.

  5. Enter or select the following information in the Networking tab.

    Setting Value
    Network interface
    Virtual network Select myVNet.
    Subnet Select myBackendSubnet (10.1.0.0/24,2404:f800:8000:122:/64).
    Public IP Select myPublicIP-IPv4.
    NIC network security group Select Advanced.
    Configure network security group Select Create new.
    Enter myNSG in Name.
    Select OK.
  6. Select Review + create.

  7. Select Create.

  8. Generate new key pair appears. Select Download private key and create resource.

  9. The private key downloads to your local computer. Copy the private key to a directory on your computer. In the following example, it's ~/.ssh.

Note

The network security group created with the virtual machine blocks all inbound access from the internet, including SSH. To connect to the virtual machine, use Azure Bastion. For more information, see Quickstart: Deploy Azure Bastion with default settings.

Configure network interface

A network interface is automatically created and attached to the chosen virtual network during creation. In this section, you add the IPv6 configuration to the existing network interface.

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

  2. Select myVM or your existing virtual machine name.

  3. Select Networking in Settings.

  4. The name of your default network interface will be myvmxx, with xx a random number. In this example, it's myvm281. Select myvm281 next to Network Interface:.

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

  6. In IP configurations, select + Add.

  7. In Add IP configuration, enter or select the following information.

    Setting Value
    Name Enter Ipv6config.
    IP version Select IPv6.
    Private IP address settings
    Allocation Leave the default of Dynamic.
    Public IP address Select Associate.
    Public IP address Select myPublicIP-IPv6.
  8. Select OK.

Install nginx

In this section, you create a network security group rule to allow HTTP traffic and install nginx on the virtual machine using the Run Command feature.

Create an inbound security rule

  1. In the search box at the top of the portal, enter Network security group. Select Network security groups in the search results.

  2. Select myNSG.

  3. Select Inbound security rules in Settings.

  4. Select + Add.

  5. Enter or select the following information:

    Setting Value
    Source Leave the default of Any.
    Source port ranges Leave the default of *.
    Destination Leave the default of Any.
    Service Select HTTP.
    Action Leave the default of Allow.
    Priority Enter 100.
    Name Enter myNSGRuleHTTP.
  6. Select Add.

Install nginx with Run Command

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

  2. Select myVM.

  3. In Operations, select Run command.

  4. Select RunShellScript.

  5. Enter the following commands:

    sudo apt-get update
    sudo apt-get install -y nginx
    
  6. Select Run.

  7. Wait for the command to complete. The output pane displays Enable succeeded when complete.

Test dual-stack connectivity

Verify nginx is running by connecting to the public IPv4 address of the virtual machine.

  1. In the search box at the top of the portal, enter Public IP address. Select Public IP addresses in the search results.

  2. Select myPublicIP-IPv4.

  3. Note the public IPv4 address in the Overview under IP address. In this example, it's 203.0.113.77.

  4. Open your web browser and browse to http://203.0.113.77. Replace the IP address with the public IPv4 address of your virtual machine.

  5. The default nginx welcome page is displayed, confirming that the web server is running and accessible over IPv4.

Clean up resources

When your finished with the resources created in this article, delete the resource group and all of the resources it contains:

  1. In the search box at the top of the portal, enter myResourceGroup. Select myResourceGroup in the search results in Resource groups.

  2. Select Delete resource group.

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

Next steps

In this article, you learned how to create an Azure Virtual machine with a dual-stack network.

For more information about IPv6 and IP addresses in Azure, see: