|
1 | 1 | ---
|
2 |
| -title: #Required; page title is displayed in search results. Include the brand. |
3 |
| -description: #Required; article description that is displayed in search results. |
4 |
| -author: #Required; your GitHub user alias, with correct capitalization. |
5 |
| -ms.author: #Required; microsoft alias of author; optional team alias. |
6 |
| -ms.service: #Required; service per approved list. slug assigned by ACOM. |
7 |
| -ms.topic: how-to #Required; leave this attribute/value as-is. |
8 |
| -ms.date: #Required; mm/dd/yyyy format. |
9 |
| -ms.custom: template-how-to #Required; leave this attribute/value as-is. |
| 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 |
10 | 12 | ---
|
11 | 13 |
|
12 |
| -<!-- |
13 |
| -Remove all the comments in this template before you sign-off or merge to the |
14 |
| -main branch. |
15 |
| ---> |
| 14 | +# Create an Azure Virtual Machine with a dual-stack network using the Azure CLI |
16 | 15 |
|
17 |
| -<!-- |
18 |
| -This template provides the basic structure of a how-to article. |
19 |
| -See the [how-to guidance](contribute-how-to-write-howto.md) in the contributor guide. |
| 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. |
20 | 17 |
|
21 |
| -To provide feedback on this template contact |
22 |
| -[the templates workgroup](mailto:[email protected]). |
23 |
| ---> |
| 18 | +## Prerequisites |
24 | 19 |
|
25 |
| -<!-- 1. H1 |
26 |
| -Required. Start your H1 with a verb. Pick an H1 that clearly conveys the task the |
27 |
| -user will complete. |
28 |
| ---> |
| 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). |
29 | 21 |
|
30 |
| -# [H1 heading here] |
| 22 | +[!INCLUDE [azure-cli-prepare-your-environment-no-header.md](azure-cli-prepare-your-environment-no-header.md)] |
| 23 | +- This tutorial requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed. |
31 | 24 |
|
32 |
| -<!-- 2. Introductory paragraph |
33 |
| -Required. Lead with a light intro that describes, in customer-friendly language, |
34 |
| -what the customer will learn, or do, or accomplish. Answer the fundamental “why |
35 |
| -would I want to do this?” question. Keep it short. |
36 |
| ---> |
37 | 25 |
|
38 |
| -[Add your introductory paragraph] |
| 26 | +## Create a resource group |
39 | 27 |
|
40 |
| -<!-- 3. Prerequisites |
41 |
| -Optional. If you need prerequisites, make them your first H2 in a how-to guide. |
42 |
| -Use clear and unambiguous language and use a list format. |
43 |
| ---> |
| 28 | +An Azure resource group is a logical container into which Azure resources are deployed and managed. |
44 | 29 |
|
45 |
| -## Prerequisites |
| 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. |
46 | 59 |
|
47 |
| -- <!-- prerequisite 1 --> |
48 |
| -- <!-- prerequisite 2 --> |
49 |
| -- <!-- prerequisite n --> |
50 |
| -<!-- remove this section if prerequisites are not needed --> |
51 |
| - |
52 |
| -<!-- 4. H2s |
53 |
| -Required. A how-to article explains how to do a task. The bulk of each H2 should be |
54 |
| -a procedure. |
55 |
| ---> |
56 |
| - |
57 |
| -## [Section 1 heading] |
58 |
| -<!-- Introduction paragraph --> |
59 |
| -1. <!-- Step 1 --> |
60 |
| -1. <!-- Step 2 --> |
61 |
| -1. <!-- Step n --> |
62 |
| - |
63 |
| -## [Section 2 heading] |
64 |
| -<!-- Introduction paragraph --> |
65 |
| -1. <!-- Step 1 --> |
66 |
| -1. <!-- Step 2 --> |
67 |
| -1. <!-- Step n --> |
68 |
| - |
69 |
| -## [Section n heading] |
70 |
| -<!-- Introduction paragraph --> |
71 |
| -1. <!-- Step 1 --> |
72 |
| -1. <!-- Step 2 --> |
73 |
| -1. <!-- Step n --> |
74 |
| - |
75 |
| -<!-- 5. Next steps |
76 |
| -Required. Provide at least one next step and no more than three. Include some |
77 |
| -context so the customer can determine why they would click the link. |
78 |
| ---> |
| 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 additional 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 crate the virtual machine and it's 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 as part of the command. 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 a SSH connection to the virtual machine by using the following command. |
| 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 | +``` |
79 | 220 |
|
80 | 221 | ## Next steps
|
81 |
| -<!-- Add a context sentence for the following links --> |
82 |
| -- [Write how-to guides](contribute-how-to-write-howto.md) |
83 |
| -- [Links](links-how-to.md) |
84 |
| - |
85 |
| -<!-- |
86 |
| -Remove all the comments in this template before you sign-off or merge to the |
87 |
| -main branch. |
88 |
| ---> |
| 222 | + |
| 223 | +In this article you learned how to create a 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