Skip to content

Commit a2defcd

Browse files
authored
Merge pull request #229612 from v-thepet/vnet1
Freshness: Create virtual network quickstarts
2 parents 7cce042 + 0282443 commit a2defcd

16 files changed

+666
-500
lines changed
81.2 KB
Loading
34.9 KB
Loading
53.2 KB
Loading
-112 KB
Loading
Binary file not shown.
Binary file not shown.
Binary file not shown.

articles/virtual-network/quick-create-bicep.md

Lines changed: 229 additions & 45 deletions
Large diffs are not rendered by default.
Lines changed: 136 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,211 @@
11
---
2-
title: 'Quickstart: Create a virtual network - Azure CLI'
2+
title: 'Quickstart: Use Azure CLI to create a virtual network'
33
titleSuffix: Azure Virtual Network
4-
description: In this quickstart, learn to create a virtual network using the Azure CLI. A virtual network lets Azure resources communicate with each other and with the internet.
4+
description: Learn how to use Azure CLI to create and connect through an Azure virtual network and virtual machines.
55
author: asudbring
66
ms.service: virtual-network
77
ms.topic: quickstart
8-
ms.date: 04/13/2022
8+
ms.date: 03/15/2023
99
ms.author: allensu
1010
ms.custom: devx-track-azurecli, mode-api
11-
#Customer intent: I want to create a virtual network so that virtual machines can communicate privately with each other and with the internet.
11+
#Customer intent: I want to use Azure CLI to create a virtual network so that virtual machines can communicate privately with each other and with the internet.
1212
---
1313

14-
# Quickstart: Create a virtual network using the Azure CLI
14+
# Quickstart: Use Azure CLI to create a virtual network
1515

16-
A virtual network enables Azure resources, like virtual machines (VMs), to communicate privately with each other, and with the internet.
16+
This quickstart shows you how to create a virtual network by using Azure CLI, the Azure command-line interface. You then create two virtual machines (VMs) in the network, securely connect to the VMs from the internet, and communicate privately between the VMs.
1717

18-
In this quickstart, you learn how to create a virtual network. After creating a virtual network, you deploy two VMs into the virtual network. You then connect to the VMs from the internet, and communicate privately over the new virtual network.
18+
A virtual network is the fundamental building block for private networks in Azure. Azure Virtual Network enables Azure resources like VMs to securely communicate with each other and the internet.
1919

20-
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
20+
## Prerequisites
2121

22-
[!INCLUDE [azure-cli-prepare-your-environment.md](~/articles/reusable-content/azure-cli/azure-cli-prepare-your-environment.md)]
22+
- An Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
2323

24-
- This quickstart requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
24+
- Azure Cloud Shell or Azure CLI.
2525

26-
## Create a resource group
26+
The steps in this quickstart run the Azure CLI commands interactively in [Azure Cloud Shell](/azure/cloud-shell/overview). To run the commands in the Cloud Shell, select **Open Cloudshell** at the upper-right corner of a code block. Select **Copy** to copy the code, and paste it into Cloud Shell to run it. You can also run the Cloud Shell from within the Azure portal.
2727

28-
Before you can create a virtual network, you have to create a resource group to host the virtual network. Create a resource group with [az group create](/cli/azure/group#az-group-create). This example creates a resource group named **CreateVNetQS-rg** in the **Eastus** location:
28+
You can also [install Azure CLI locally](/cli/azure/install-azure-cli) to run the commands. The steps in this article require Azure CLI version 2.0.28 or later. Run [az version](/cli/azure/reference-index?#az-version) to find your installed version and dependent libraries, and run [az upgrade](/cli/azure/reference-index?#az-upgrade) to upgrade.
2929

30-
```azurecli-interactive
31-
az group create \
32-
--name CreateVNetQS-rg \
33-
--location eastus
34-
```
30+
If you use a local installation, sign in to Azure by using the [az login](/cli/azure/reference-index#az-login) command.
3531

36-
## Create a virtual network
32+
## Create a virtual network and subnet
3733

38-
Create a virtual network with [az network vnet create](/cli/azure/network/vnet#az-network-vnet-create). This example creates a default virtual network named **myVNet** with one subnet named **default** .
34+
1. First, use [az group create](/cli/azure/group#az-group-create) to create a resource group to host the virtual network. Run the following code to create a resource group named `TestRG` in the `eastus` Azure region.
3935

40-
```azurecli-interactive
41-
az network vnet create \
42-
--name myVNet \
43-
--resource-group CreateVNetQS-rg \
44-
--subnet-name default
45-
```
36+
```azurecli-interactive
37+
az group create \
38+
--name TestRG \
39+
--location eastus
40+
```
4641

47-
## Create virtual machines
42+
1. Use [az network vnet create](/cli/azure/network/vnet#az-network-vnet-create) to create a virtual network named `VNet` with a subnet named `default` in the `TestRG` resource group.
4843

49-
Create two VMs in the virtual network.
44+
```azurecli-interactive
45+
az network vnet create \
46+
--name VNet \
47+
--resource-group TestRG \
48+
--address-prefix 10.0.0.0/16 \
49+
--subnet-name default \
50+
--subnet-prefixes 10.0.0.0/24
51+
```
5052

51-
### Create the first VM
53+
## Deploy Azure Bastion
5254

53-
Create a VM with [az vm create](/cli/azure/vm#az-vm-create).
55+
Azure Bastion uses your browser to connect to VMs in your virtual network over secure shell (SSH) or remote desktop protocol (RDP) by using their private IP addresses. The VMs don't need public IP addresses, client software, or special configuration. For more information about Azure Bastion, see [Azure Bastion](~/articles/bastion/bastion-overview.md).
5456

55-
If SSH keys don't already exist in a default key location, the command creates them. To use a specific set of keys, use the `--ssh-key-value` option.
57+
1. Use [az network vnet subnet create](/cli/azure/network/vnet/subnet#az-network-vnet-subnet-create) to create an Azure Bastion subnet for your virtual network. This subnet is reserved exclusively for Azure Bastion resources and must be named `AzureBastionSubnet`.
5658

57-
The `--no-wait` option creates the VM in the background. You can continue to the next step.
59+
```azurecli-interactive
60+
az network vnet subnet create \
61+
--name AzureBastionSubnet \
62+
--resource-group TestRG \
63+
--vnet-name VNet \
64+
--address-prefix 10.0.1.0/26 \
65+
--location eastus
66+
```
5867

59-
This example creates a VM named **myVM1**:
68+
1. Create a public IP address for Azure Bastion. The bastion host uses the public IP to access secure shell (SSH) and remote desktop protocol (RDP) over port 443.
6069

61-
```azurecli-interactive
62-
az vm create \
63-
--resource-group CreateVNetQS-rg \
64-
--name myVM1 \
65-
--image UbuntuLTS \
66-
--generate-ssh-keys \
67-
--public-ip-address myPublicIP-myVM1 \
68-
--no-wait
69-
```
70+
```azurecli-interactive
71+
az network public-ip create --resource-group TestRG --name VNet-ip --sku Standard --location eastus
72+
```
7073

71-
### Create the second VM
74+
1. Use [az network bastion create](/cli/azure/network/bastion#az-network-bastion-create) to create an Azure Bastion host in the AzureBastionSubnet of your virtual network.
7275

73-
You used the `--no-wait` option in the previous step. You can go ahead and create the second VM named **myVM2**.
76+
```azurecli-interactive
77+
az network bastion create \
78+
--name VNet-bastion \
79+
--public-ip-address VNet-ip \
80+
--resource-group TestRG \
81+
--vnet-name VNet --location eastus
82+
```
7483

75-
```azurecli-interactive
76-
az vm create \
77-
--resource-group CreateVNetQS-rg \
78-
--name myVM2 \
79-
--image UbuntuLTS \
80-
--public-ip-address myPublicIP-myVM2 \
81-
--generate-ssh-keys
82-
```
84+
It takes about 10 minutes for the Bastion resources to deploy. You can create VMs in the next section while Bastion deploys to your virtual network.
85+
86+
## Create virtual machines
87+
88+
Use [az vm create](/cli/azure/vm#az-vm-create) to create two VMs named `VM1` and `VM2` in the `default` subnet of the virtual network. When you're prompted for credentials, enter user names and passwords for the VMs.
89+
90+
1. To create the first VM, run the following command:
91+
92+
```azurecli-interactive
93+
az vm create \
94+
--resource-group TestRG \
95+
--name VM1 \
96+
--image Win2019Datacenter
97+
```
8398

84-
[!INCLUDE [ephemeral-ip-note.md](../../includes/ephemeral-ip-note.md)]
99+
1. To create the second VM, run the following command:
85100

86-
### Azure CLI output message
101+
```azurecli-interactive
102+
az vm create \
103+
--resource-group TestRG \
104+
--name VM2 \
105+
--image Win2019Datacenter
106+
```
87107

88-
The VMs take a few minutes to create. After Azure creates the VMs, the Azure CLI returns output like this:
108+
>[!TIP]
109+
>You can also use the `--no-wait` option to create a VM in the background while you continue with other tasks.
110+
111+
The VMs take a few minutes to create. After Azure creates each VM, Azure CLI returns output similar to the following message:
89112

90113
```output
91114
{
92115
"fqdns": "",
93-
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/CreateVNetQS-rg/providers/Microsoft.Compute/virtualMachines/myVM2",
116+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/CreateVNetQS-rg/providers/Microsoft.Compute/virtualMachines/VM2",
94117
"location": "eastus",
95118
"macAddress": "00-0D-3A-23-9A-49",
96119
"powerState": "VM running",
97120
"privateIpAddress": "10.0.0.5",
98121
"publicIpAddress": "40.68.254.142",
99-
"resourceGroup": "CreateVNetQS-rg"
122+
"resourceGroup": "TestRG"
100123
"zones": ""
101124
}
102125
```
103126

104-
## VM public IP
127+
>[!NOTE]
128+
>VMs in a virtual network with a Bastion host don't need public IP addresses. Bastion provides the public IP, and the VMs use private IPs to communicate within the network. You can remove the public IPs from any VMs in Bastion-hosted virtual networks. For more information, see [Dissociate a public IP address from an Azure VM](ip-services/remove-public-ip-address-vm.md).
105129
106-
To get the public IP address **myVM2**, use [az network public-ip show](/cli/azure/network/public-ip#az-network-public-ip-show):
130+
## Connect to a VM
107131

108-
```azurecli-interactive
109-
az network public-ip show \
110-
--resource-group CreateVNetQS-rg \
111-
--name myPublicIP-myVM2 \
112-
--query ipAddress \
113-
--output tsv
114-
```
132+
1. In the [Azure portal](https://portal.azure.com), search for and select **Virtual machines**.
115133

116-
## Connect to a VM from the internet
134+
1. On the **Virtual machines** page, select **VM1**.
117135

118-
In this command, replace `<publicIpAddress>` with the public IP address of your **myVM2** VM:
136+
1. At the top of the **VM1** page, select **Connect**.
119137

120-
```bash
121-
ssh <publicIpAddress>
122-
```
138+
1. On the **Connect** page, select **More ways to connect**, and then select **Go to Bastion**.
139+
140+
:::image type="content" source="./media/quick-create-portal/connect-to-virtual-machine.png" alt-text="Screenshot of connecting to VM1 with Azure Bastion." border="true":::
141+
142+
1. On the **Bastion** page, enter the username and password you created for the VM, and then select **Connect**.
123143

124144
## Communicate between VMs
125145

126-
To confirm private communication between the **myVM2** and **myVM1** VMs, enter `ping myVM1 -c 4`.
146+
1. From the desktop of VM1, open a command prompt and enter `ping myVM2`. You get a reply similar to the following message:
127147

128-
You'll receive a reply message like this:
148+
```cmd
149+
C:\windows\system32>ping VM2
150+
151+
Pinging VM2.ovvzzdcazhbu5iczfvonhg2zrb.bx.internal.cloudapp.net with 32 bytes of data:
152+
Request timed out.
153+
Request timed out.
154+
Request timed out.
155+
Request timed out.
156+
157+
Ping statistics for 10.0.0.5:
158+
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
159+
```
129160

130-
```bash
161+
The ping fails because it uses the Internet Control Message Protocol (ICMP). By default, ICMP isn't allowed through Windows firewall.
131162

132-
azureuser@myVM2:~$ ping myVM1 -c 4
133-
PING myVM1.h0o2foz2r0tefncddcnfqm2lid.bx.internal.cloudapp.net (10.0.0.4) 56(84) bytes of data.
134-
64 bytes from myvm1.internal.cloudapp.net (10.0.0.4): icmp_seq=1 ttl=64 time=2.77 ms
135-
64 bytes from myvm1.internal.cloudapp.net (10.0.0.4): icmp_seq=2 ttl=64 time=1.95 ms
136-
64 bytes from myvm1.internal.cloudapp.net (10.0.0.4): icmp_seq=3 ttl=64 time=2.19 ms
137-
64 bytes from myvm1.internal.cloudapp.net (10.0.0.4): icmp_seq=4 ttl=64 time=1.85 ms
163+
1. To allow ICMP to inbound through Windows firewall on this VM, enter the following command:
138164

139-
--- myVM1.h0o2foz2r0tefncddcnfqm2lid.bx.internal.cloudapp.net ping statistics ---
140-
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
141-
rtt min/avg/max/mdev = 1.859/2.195/2.770/0.357 ms
165+
```cmd
166+
netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow
167+
```
142168

143-
```
169+
1. Close the remote desktop connection to VM1.
144170

145-
Exit the SSH session with the **myVM2** VM.
171+
1. Repeat the steps in [Connect to a VM](#connect-to-a-vm) to connect to VM2.
172+
173+
1. On VM2, from a command prompt, enter `ping VM1`.
174+
175+
This time you get a success reply similar to the following message, because you allowed ICMP through the firewall on VM1.
176+
177+
```cmd
178+
C:\windows\system32>ping VM1
179+
180+
Pinging VM1.e5p2dibbrqtejhq04lqrusvd4g.bx.internal.cloudapp.net [10.0.0.4] with 32 bytes of data:
181+
Reply from 10.0.0.4: bytes=32 time=2ms TTL=128
182+
Reply from 10.0.0.4: bytes=32 time<1ms TTL=128
183+
Reply from 10.0.0.4: bytes=32 time<1ms TTL=128
184+
Reply from 10.0.0.4: bytes=32 time<1ms TTL=128
185+
186+
Ping statistics for 10.0.0.4:
187+
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
188+
Approximate round trip times in milli-seconds:
189+
Minimum = 0ms, Maximum = 2ms, Average = 0ms
190+
```
191+
192+
1. Close the remote desktop connection to VM2.
146193

147194
## Clean up resources
148195

149-
When no longer needed, you can use [az group delete](/cli/azure/group#az-group-delete) to remove the resource group and all the resources it has:
196+
When you're done with the virtual network and the VMs, use [az group delete](/cli/azure/group#az-group-delete) to remove the resource group and all its resources.
150197

151198
```azurecli-interactive
152199
az group delete \
153-
--name CreateVNetQS-rg \
200+
--name TestRG \
154201
--yes
155202
```
156203

157204
## Next steps
158205

159-
In this quickstart:
206+
In this quickstart, you created a virtual network with a default subnet that contains two VMs. You deployed Azure Bastion and used it to connect to the VMs, and securely communicated between the VMs. To learn more about virtual network settings, see [Create, change, or delete a virtual network](manage-virtual-network.md).
160207

161-
* You created a default virtual network and two VMs.
162-
* You connected to one VM from the internet and communicated privately between the two VMs.
163-
164-
Private communication between VMs is unrestricted in a virtual network.
165-
166-
Advance to the next article to learn more about configuring different types of VM network communications:
208+
Private communication between VMs in a virtual network is unrestricted by default. Continue to the next article to learn more about configuring different types of VM network communications.
167209
> [!div class="nextstepaction"]
168210
> [Filter network traffic](tutorial-filter-network-traffic.md)
211+

0 commit comments

Comments
 (0)