You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Customer intent: As a cloud engineer, I want to create a virtual machine with a dual-stack network in Azure using the portal, CLI, or PowerShell, so that I can ensure both IPv4 and IPv6 connectivity for my applications.
13
13
---
@@ -47,8 +47,26 @@ If you choose to install and use PowerShell locally, this article requires the A
47
47
48
48
In this section, you create a resource group and dual-stack virtual network for the virtual machine in the Azure portal.
49
49
50
+
### Create a resource group
51
+
50
52
1. Sign-in to the [Azure portal](https://portal.azure.com).
51
53
54
+
1. In the portal, search for and select **Resource groups**.
55
+
56
+
1. Select **+ Create**.
57
+
58
+
1. On the **Basics** tab, enter or select the following values:
59
+
60
+
| Setting | Value |
61
+
| ------- | ----- |
62
+
|**Subscription**| Select your subscription. |
63
+
|**Resource group**| Enter *myResourceGroup*. |
64
+
|**Region**| Select **(US) East US 2**. |
65
+
66
+
1. Select **Review + create**, and then select **Create**.
67
+
68
+
### Create a virtual network
69
+
52
70
1. In the search box at the top of the portal, enter **Virtual network**. Select **Virtual networks** in the search results.
53
71
54
72
1. Select **+ Create**.
@@ -59,7 +77,7 @@ In this section, you create a resource group and dual-stack virtual network for
59
77
| ------- | ----- |
60
78
|**Project details**||
61
79
| Subscription | Select your subscription. |
62
-
| Resource group | Select **Create new**. </br> In **Name**, enter **myResourceGroup**. </br> Select **OK**. |
80
+
| Resource group | Select **myResourceGroup**. |
63
81
|**Instance details**||
64
82
| Name | Enter **myVNet**. |
65
83
| Region | Select **East US 2**. |
@@ -317,6 +335,9 @@ In this section, you create the virtual machine and its supporting resources.
317
335
318
336
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**.
319
337
338
+
> [!NOTE]
339
+
> 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](../../bastion/quickstart-host-portal.md).
340
+
320
341
### Configure network interface
321
342
322
343
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.
@@ -350,6 +371,19 @@ A network interface is automatically created and attached to the chosen virtual
350
371
351
372
In this section, you create the virtual machine and its supporting resources.
352
373
374
+
### Create a network security group
375
+
376
+
Create a network security group with [az network nsg create](/cli/azure/network/nsg#az-network-nsg-create). The default rules in the network security group deny all inbound access from the internet.
377
+
378
+
```azurecli-interactive
379
+
az network nsg create \
380
+
--resource-group myResourceGroup \
381
+
--name myNSG
382
+
```
383
+
384
+
> [!NOTE]
385
+
> The default rules of the network security group block 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](../../bastion/quickstart-host-portal.md).
386
+
353
387
### Create network interface
354
388
355
389
You 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.
@@ -398,6 +432,22 @@ Use [az vm create](/cli/azure/vm#az-vm-create) to create the virtual machine.
398
432
399
433
In this section, you create the virtual machine and its supporting resources.
400
434
435
+
### Create a network security group
436
+
437
+
Create a network security group with [New-AzNetworkSecurityGroup](/powershell/module/az.network/new-aznetworksecuritygroup). The default rules in the network security group deny all inbound access from the internet.
438
+
439
+
```azurepowershell-interactive
440
+
$nsg = @{
441
+
Name = 'myNSG'
442
+
ResourceGroupName = 'myResourceGroup'
443
+
Location = 'eastus2'
444
+
}
445
+
New-AzNetworkSecurityGroup @nsg
446
+
```
447
+
448
+
> [!NOTE]
449
+
> The default rules of the network security group block 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](../../bastion/quickstart-host-portal.md).
450
+
401
451
### Create network interface
402
452
403
453
You use [New-AzNetworkInterface](/powershell/module/az.network/new-aznetworkinterface) and [New-AzNetworkInterfaceIpConfig](/powershell/module/az.network/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.
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.
520
572
521
573
# [Azure portal](#tab/azureportal)
522
574
523
-
You connect to the virtual machine with SSH to test the IPv4 public IP address.
575
+
### Create an inbound security rule
524
576
525
-
1. In the search box at the top of the portal, enter **Public IP address**. Select **Public IP addresses** in the search results.
577
+
1. In the search box at the top of the portal, enter **Network security group**. Select **Network security groups** in the search results.
578
+
579
+
1. Select **myNSG**.
580
+
581
+
1. Select **Inbound security rules** in **Settings**.
582
+
583
+
1. Select **+ Add**.
584
+
585
+
1. Enter or select the following information:
586
+
587
+
| Setting | Value |
588
+
| ------- | ----- |
589
+
| Source | Leave the default of **Any**. |
590
+
| Source port ranges | Leave the default of **\***. |
591
+
| Destination | Leave the default of **Any**. |
592
+
| Service | Select **HTTP**. |
593
+
| Action | Leave the default of **Allow**. |
594
+
| Priority | Enter **100**. |
595
+
| Name | Enter *myNSGRuleHTTP*. |
596
+
597
+
1. Select **Add**.
598
+
599
+
### Install nginx with Run Command
600
+
601
+
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
602
+
603
+
1. Select **myVM**.
526
604
527
-
2. Select**myPublicIP-IPv4**.
605
+
1. In**Operations**, select **Run command**.
528
606
529
-
3. The public IPv4 address is in the **Overview** in **IP address**. In this example it's, **20.22.46.19**.
607
+
1. Select **RunShellScript**.
530
608
531
-
4. 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**.
1. Wait for the command to complete. The output pane displays **Enable succeeded** when complete.
619
+
536
620
# [Azure CLI](#tab/azurecli/)
537
621
538
-
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.
622
+
### Create an inbound security rule
623
+
624
+
Use [az network nsg rule create](/cli/azure/network/nsg/rule#az-network-nsg-rule-create) to create a network security group rule to allow HTTP traffic.
539
625
540
626
```azurecli-interactive
541
-
az network public-ip show \
627
+
az network nsg rule create \
542
628
--resource-group myResourceGroup \
543
-
--name myPublicIP-IPv4 \
544
-
--query ipAddress \
545
-
--output tsv
629
+
--nsg-name myNSG \
630
+
--name myNSGRuleHTTP \
631
+
--protocol '*' \
632
+
--direction inbound \
633
+
--source-address-prefix '*' \
634
+
--source-port-range '*' \
635
+
--destination-address-prefix '*' \
636
+
--destination-port-range 80 \
637
+
--access allow \
638
+
--priority 100
546
639
```
547
640
641
+
### Install nginx
642
+
643
+
Use [az vm run-command invoke](/cli/azure/vm/run-command#az-vm-run-command-invoke) to install nginx on the virtual machine.
Use [Get-AzNetworkSecurityGroup](/powershell/module/az.network/get-aznetworksecuritygroup) and [Add-AzNetworkSecurityRuleConfig](/powershell/module/az.network/add-aznetworksecurityruleconfig) to create a network security group rule to allow HTTP traffic.
658
+
659
+
```azurepowershell-interactive
660
+
## Place the network security group into a variable. ##
0 commit comments