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
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.
552
572
553
573
# [Azure portal](#tab/azureportal)
554
574
555
-
You connect to the virtual machine with SSH to test the IPv4 public IP address.
575
+
### Create an inbound security rule
556
576
557
-
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**.
558
604
559
-
2. Select**myPublicIP-IPv4**.
605
+
1. In**Operations**, select **Run command**.
560
606
561
-
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**.
562
608
563
-
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
+
568
620
# [Azure CLI](#tab/azurecli/)
569
621
570
-
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.
571
625
572
626
```azurecli-interactive
573
-
az network public-ip show \
627
+
az network nsg rule create \
574
628
--resource-group myResourceGroup \
575
-
--name myPublicIP-IPv4 \
576
-
--query ipAddress \
577
-
--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
578
639
```
579
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