Beginner · Security · 6 of 15

Create and attach an NSG

Your tasks
  • Create the NSG nsg-web
  • Attach nsg-web to subnet-web

Security wants a network security group (NSG, a set of allow and deny rules) in front of subnet-web, where vm-web serves HTTPS. Create nsg-web, attach it to subnet-web, and look at the rules it starts with. vm-client in subnet-client, in the same VNet, should still reach vm-web afterward. Find out which rule allows it.

You'll learn
Network security groups
  1. Create the NSG.

    az network nsg create -g rg-lab --name nsg-web
    What's this?

    Creates a network security group. It filters nothing until you attach it to a subnet or a network interface.

    • -g the resource group the resources live in
    • --name the name of the thing to look at or change
  2. List its rules including the defaults.

    az network nsg rule list -g rg-lab --nsg-name nsg-web --include-default -o table
    What's this?

    Lists the rules in a network security group, so you can read them in priority order.

    • -g the resource group the resources live in
    • --nsg-name the network security group the rule is in
    • --include-default also show the built-in default rules
  3. Attach it to subnet-web.

    az network vnet subnet update -g rg-lab --vnet-name vnet-app --name subnet-web --network-security-group nsg-web
    What's this?

    Changes a subnet's settings, such as which NSG or route table is attached to it.

    • -g the resource group the resources live in
    • --vnet-name the virtual network
    • --name the name of the thing to look at or change
  4. Answer question 1 from the table in step 2. For question 2, find the default rule that matches traffic from inside the VNet.

    Priority
    A number on each rule that sets the order Azure checks the rules in.
    Default rule
    A rule Azure puts in every NSG. You can't delete it.
    Default rule
    A rule Azure puts in every NSG. You can't delete it.
Sources on Microsoft Learn (3)
0/2 changes
Network map
?
  • Resource group, the outer dashed frame
  • Virtual network, with its address space top right
  • Subnet, with range and usable IPs (5 reserved)
  • Network security group. A small shield on a VM's NIC means the NIC has one too
  • Route table on the subnet
  • NICVM Appliance Private endpoint
  • Peering Connected Initiated or access off
  • Goal working Goal broken, X marks where it stops
  • Private DNS zone, dotted lines go to linked VNets
  • Orange pulse: what your last command changed. Drag to pan, Ctrl and scroll to zoom.
Resource grouprg-labvnet-app: tap to inspectVirtual networkvnet-app10.1.0.0/16subnet-web: tap to inspectsubnet-web10.1.1.0/24 · 251 usablevm-web 10.1.1.4: tap to inspectNICvm-web10.1.1.4subnet-client: tap to inspectsubnet-client10.1.2.0/24 · 251 usablevm-client 10.1.2.4: tap to inspectNICvm-client10.1.2.4:443 ✓
  • vm-client → vm-web:443should work: working
Goals 0/4
Cloud Shell · bashVMsrg-lab · eastus2
cloudshell:~$