|
| 1 | +--- |
| 2 | +title: Create an Azure virtual machine with a dual-stack network - Azure CLI |
| 3 | +titleSuffix: Azure Virtual Network |
| 4 | +description: In this article, learn how to use the Azure CLI to create a virtual machine with a dual-stack virtual network in Azure. |
| 5 | +author: asudbring |
| 6 | +ms.author: allensu |
| 7 | +ms.service: virtual-network |
| 8 | +ms.subservice: ip-services |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 11/11/2021 |
| 11 | +ms.custom: template-how-to |
| 12 | +--- |
| 13 | + |
| 14 | +# Create an Azure Virtual Machine with a dual-stack network using the Azure CLI |
| 15 | + |
| 16 | +In this article, you'll create a virtual machine in Azure with the Azure CLI. The virtual machine is created along with the dual-stack network as part of the procedures. When completed, the virtual machine supports IPv4 and IPv6 communication. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). |
| 21 | + |
| 22 | +[!INCLUDE [azure-cli-prepare-your-environment-no-header.md](../../../includes/azure-cli-prepare-your-environment-no-header.md)] |
| 23 | + |
| 24 | +- This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed. |
| 25 | + |
| 26 | +## Create a resource group |
| 27 | + |
| 28 | +An Azure resource group is a logical container into which Azure resources are deployed and managed. |
| 29 | + |
| 30 | +Create a resource group with [az group create](/cli/azure/group#az_group_create) named **myResourceGroup** in the **eastus2** location. |
| 31 | + |
| 32 | +```azurecli-interactive |
| 33 | + az group create \ |
| 34 | + --name myResourceGroup \ |
| 35 | + --location eastus2 |
| 36 | +``` |
| 37 | + |
| 38 | +## Create a virtual network |
| 39 | + |
| 40 | +In this section, you'll create a dual-stack virtual network for the virtual machine. |
| 41 | + |
| 42 | +Use [az network vnet create](/cli/azure/network/vnet#az_network_vnet_create) to create a virtual network. |
| 43 | + |
| 44 | +```azurecli-interactive |
| 45 | + az network vnet create \ |
| 46 | + --resource-group myResourceGroup \ |
| 47 | + --location eastus2 \ |
| 48 | + --name myVNet \ |
| 49 | + --address-prefixes 10.0.0.0/16 2404:f800:8000:122::/63 \ |
| 50 | + --subnet-name myBackendSubnet \ |
| 51 | + --subnet-prefixes 10.0.0.0/24 2404:f800:8000:122::/64 |
| 52 | +``` |
| 53 | + |
| 54 | +## Create public IP addresses |
| 55 | + |
| 56 | +You'll create two public IP addresses in this section, IPv4 and IPv6. |
| 57 | + |
| 58 | +Use [az network public-ip create](/cli/azure/network/public-ip#az_network_public_ip_create) to create the public IP addresses. |
| 59 | + |
| 60 | +```azurecli-interactive |
| 61 | + az network public-ip create \ |
| 62 | + --resource-group myResourceGroup \ |
| 63 | + --name myPublicIP-Ipv4 \ |
| 64 | + --sku Standard \ |
| 65 | + --version IPv4 |
| 66 | +
|
| 67 | + az network public-ip create \ |
| 68 | + --resource-group myResourceGroup \ |
| 69 | + --name myPublicIP-Ipv6 \ |
| 70 | + --sku Standard \ |
| 71 | + --version IPv6 |
| 72 | +
|
| 73 | +``` |
| 74 | +## Create a network security group |
| 75 | + |
| 76 | +In this section, you'll create a network security group for the virtual machine and virtual network. |
| 77 | + |
| 78 | +Use [az network nsg create](/cli/azure/network/nsg#az_network_nsg_create) to create the network security group. |
| 79 | + |
| 80 | +```azurecli-interactive |
| 81 | + az network nsg create \ |
| 82 | + --resource-group myResourceGroup \ |
| 83 | + --name myNSG |
| 84 | +``` |
| 85 | + |
| 86 | +### Create network security group rules |
| 87 | + |
| 88 | +You'll create a rule to allow connections to the virtual machine on port 22 for SSH. An extra rule is created to allow all ports for outbound connections. |
| 89 | + |
| 90 | +Use [az network nsg rule create](/cli/azure/network/nsg/rule#az_network_nsg_rule_create) to create the network security group rules. |
| 91 | + |
| 92 | +```azurecli-interactive |
| 93 | + az network nsg rule create \ |
| 94 | + --resource-group myResourceGroup \ |
| 95 | + --nsg-name myNSG \ |
| 96 | + --name myNSGRuleSSH \ |
| 97 | + --protocol '*' \ |
| 98 | + --direction inbound \ |
| 99 | + --source-address-prefix '*' \ |
| 100 | + --source-port-range '*' \ |
| 101 | + --destination-address-prefix '*' \ |
| 102 | + --destination-port-range 22 \ |
| 103 | + --access allow \ |
| 104 | + --priority 200 |
| 105 | +
|
| 106 | + az network nsg rule create \ |
| 107 | + --resource-group myResourceGroup \ |
| 108 | + --nsg-name myNSG \ |
| 109 | + --name myNSGRuleAllOUT \ |
| 110 | + --protocol '*' \ |
| 111 | + --direction outbound \ |
| 112 | + --source-address-prefix '*' \ |
| 113 | + --source-port-range '*' \ |
| 114 | + --destination-address-prefix '*' \ |
| 115 | + --destination-port-range '*' \ |
| 116 | + --access allow \ |
| 117 | + --priority 200 |
| 118 | +``` |
| 119 | + |
| 120 | +## Create virtual machine |
| 121 | + |
| 122 | +In this section, you'll create the virtual machine and its supporting resources. |
| 123 | + |
| 124 | +### Create network interface |
| 125 | + |
| 126 | +You'll use [az network nic create](/cli/azure/network/nic#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. |
| 127 | + |
| 128 | +```azurecli-interactive |
| 129 | + az network nic create \ |
| 130 | + --resource-group myResourceGroup \ |
| 131 | + --name myNIC1 \ |
| 132 | + --vnet-name myVNet \ |
| 133 | + --subnet myBackEndSubnet \ |
| 134 | + --network-security-group myNSG \ |
| 135 | + --public-ip-address myPublicIP-IPv4 |
| 136 | +``` |
| 137 | + |
| 138 | +### Create IPv6 IP configuration |
| 139 | + |
| 140 | +Use [az network nic ip-config create](/cli/azure/network/nic/ip-config#az_network_nic_ip_config_create) to create the IPv6 configuration for the NIC. |
| 141 | + |
| 142 | +```azurecli-interactive |
| 143 | + az network nic ip-config create \ |
| 144 | + --resource-group myResourceGroup \ |
| 145 | + --name myIPv6config \ |
| 146 | + --nic-name myNIC1 \ |
| 147 | + --private-ip-address-version IPv6 \ |
| 148 | + --vnet-name myVNet \ |
| 149 | + --subnet myBackendSubnet \ |
| 150 | + --public-ip-address myPublicIP-IPv6 |
| 151 | +``` |
| 152 | + |
| 153 | +### Create VM |
| 154 | + |
| 155 | +Use [az vm create](/cli/azure/vm#az_vm_create) to create the virtual machine. |
| 156 | + |
| 157 | +```azurecli-interactive |
| 158 | + az vm create \ |
| 159 | + --resource-group myResourceGroup \ |
| 160 | + --name myVM \ |
| 161 | + --nics myNIC1 \ |
| 162 | + --image UbuntuLTS \ |
| 163 | + --admin-username azureuser \ |
| 164 | + --authentication-type ssh \ |
| 165 | + --generate-ssh-keys |
| 166 | +``` |
| 167 | + |
| 168 | +## Test SSH connection |
| 169 | + |
| 170 | +Use [az network public-ip show](/cli/azure/network/public-ip#az_network_public_ip_show) to display the IP addresses of the virtual machine. |
| 171 | + |
| 172 | +```azurecli-interactive |
| 173 | + az network public-ip show \ |
| 174 | + --resource-group myResourceGroup \ |
| 175 | + --name myPublicIP-IPv4 \ |
| 176 | + --query ipAddress \ |
| 177 | + --output tsv |
| 178 | +``` |
| 179 | + |
| 180 | +```bash |
| 181 | +user@Azure:~$ az network public-ip show \ |
| 182 | +> --resource-group myResourceGroup \ |
| 183 | +> --name myPublicIP-IPv4 \ |
| 184 | +> --query ipAddress \ |
| 185 | +> --output tsv |
| 186 | +20.119.201.208 |
| 187 | +``` |
| 188 | + |
| 189 | +```azurecli-interactive |
| 190 | + az network public-ip show \ |
| 191 | + --resource-group myResourceGroup \ |
| 192 | + --name myPublicIP-IPv6 \ |
| 193 | + --query ipAddress \ |
| 194 | + --output tsv |
| 195 | +``` |
| 196 | + |
| 197 | +```bash |
| 198 | +user@Azure:~$ az network public-ip show \ |
| 199 | +> --resource-group myResourceGroup \ |
| 200 | +> --name myPublicIP-IPv6 \ |
| 201 | +> --query ipAddress \ |
| 202 | +> --output tsv |
| 203 | +2603:1030:408:6::9d |
| 204 | +``` |
| 205 | + |
| 206 | +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. |
| 207 | + |
| 208 | +```bash |
| 209 | + |
| 210 | +``` |
| 211 | + |
| 212 | +## Clean up resources |
| 213 | + |
| 214 | +When no longer needed, use the [az group delete](/cli/azure/group#az_group_delete) command to remove the resource group, virtual machine, and all related resources. |
| 215 | + |
| 216 | +```azurecli-interactive |
| 217 | + az group delete \ |
| 218 | + --name myResourceGroup |
| 219 | +``` |
| 220 | + |
| 221 | +## Next steps |
| 222 | + |
| 223 | +In this article, you learned how to create an Azure Virtual machine with a dual-stack network. |
| 224 | + |
| 225 | +For more information about IPv6 and IP addresses in Azure, see: |
| 226 | + |
| 227 | +- [Overview of IPv6 for Azure Virtual Network.](ipv6-overview.md) |
| 228 | + |
| 229 | +- [What is Azure Virtual Network IP Services?](ip-services-overview.md) |
| 230 | + |
| 231 | + |
0 commit comments