Create an Azure Virtual Machine with a dual-stack network
Článok
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.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
Azure PowerShell installed locally or Azure Cloud Shell.
Sign in to Azure PowerShell and select the subscription you want to use. For more information, see Sign in with Azure PowerShell.
Ensure your Az. Network module is 4.3.0 or later. To verify the installed module, use the command Get-InstalledModule -Name "Az.Network". If the module requires an update, use the command Update-Module -Name "Az. Network".
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run Get-Module -ListAvailable Az to find the installed version. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount to create a connection with Azure.
Select Create new. Enter myNSG in Name. Select OK.
Select Review + create.
Select Create.
Generate new key pair appears. Select Download private key and create resource.
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.
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.
In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.
Select myVM or your existing virtual machine name.
Select Networking in Settings.
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:.
In the properties of the network interface, select IP configurations in Settings.
In IP configurations, select + Add.
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.
Select OK.
In this section, you create the virtual machine and its supporting resources.
Create network interface
You use az network nic create to create the network interface for the virtual machine. The public IP addresses and the NSG created previously are associated with the NIC. The network interface is attached to the virtual network you created previously.
In this section, you create the virtual machine and its supporting resources.
Create network interface
You use New-AzNetworkInterface and New-AzNetworkInterfaceIpConfig to create the network interface for the virtual machine. The public IP addresses and the NSG created previously are associated with the NIC. The network interface is attached to the virtual network you created previously.
## Place the virtual network into a variable. ##
$net = @{
Name = 'myVNet'
ResourceGroupName = 'myResourceGroup'
}
$vnet = Get-AzVirtualNetwork @net
## Place the network security group into a variable. ##
$ns = @{
Name = 'myNSG'
ResourceGroupName = 'myResourceGroup'
}
$nsg = Get-AzNetworkSecurityGroup @ns
## Place the IPv4 public IP address into a variable. ##
$pub4 = @{
Name = 'myPublicIP-IPv4'
ResourceGroupName = 'myResourceGroup'
}
$pubIPv4 = Get-AzPublicIPAddress @pub4
## Place the IPv6 public IP address into a variable. ##
$pub6 = @{
Name = 'myPublicIP-IPv6'
ResourceGroupName = 'myResourceGroup'
}
$pubIPv6 = Get-AzPublicIPAddress @pub6
## Create IPv4 configuration for NIC. ##
$IP4c = @{
Name = 'ipconfig-ipv4'
Subnet = $vnet.Subnets[0]
PrivateIpAddressVersion = 'IPv4'
PublicIPAddress = $pubIPv4
}
$IPv4Config = New-AzNetworkInterfaceIpConfig @IP4c
## Create IPv6 configuration for NIC. ##
$IP6c = @{
Name = 'ipconfig-ipv6'
Subnet = $vnet.Subnets[0]
PrivateIpAddressVersion = 'IPv6'
PublicIPAddress = $pubIPv6
}
$IPv6Config = New-AzNetworkInterfaceIpConfig @IP6c
## Command to create network interface for VM ##
$nic = @{
Name = 'myNIC1'
ResourceGroupName = 'myResourceGroup'
Location = 'eastus2'
NetworkSecurityGroup = $nsg
IpConfiguration = $IPv4Config,$IPv6Config
}
New-AzNetworkInterface @nic
Create virtual machine
Use the following commands to create the virtual machine:
You connect to the virtual machine with SSH to test the IPv4 public IP address.
In the search box at the top of the portal, enter Public IP address. Select Public IP addresses in the search results.
Select myPublicIP-IPv4.
The public IPv4 address is in the Overview in IP address. In this example it's, 20.22.46.19.
Open an SSH connection to the virtual machine by using the following command. Replace the IP address with the IP address of your virtual machine. Replace azureuser with the username you chose during virtual machine creation. The -i is the path to the private key that you downloaded earlier. In this example, it's ~/.ssh/mySSHKey.pem.