Skip to content

Lab 04: Build and secure your networks

At a glance

  • Time: about 60 minutes
  • Region: Southeast Asia
  • You create: 2 virtual networks, 1 application security group, 1 network security group and 1 private DNS zone. All are free.
  • Clean up: delete everything you created at the end

What you will learn

  • How to plan and create virtual networks and subnets with address ranges.
  • How to filter traffic with a network security group (NSG) and an application security group (ASG).
  • How a private DNS zone gives names to resources inside your virtual networks.

What is different in this environment

  • You work in your own resource group in Southeast Asia. You don't create a resource group.
  • There is no public DNS zone in this lab. A public zone needs a domain name that you own. Your trainer will show it; you do the private zone.
  • You deploy the second virtual network from a template that is on this page, instead of editing the exported file on your computer.
Diagram: hq-vnet and warehouse-vnet in your resource group, the network security group nsg-apps linked to apps-subnet with an application security group, and a private DNS zone linked to warehouse-vnet.
The two virtual networks, the network security group with its application security group, and the private DNS zone you build. Select the diagram to open it full size.

Before you start

  • You are signed in to the lab directory (Getting started).
  • Your lab resource group is rg-CLOUD-LAB-GRP-N. Replace N with your group number.
  • Delete the virtual networks from Lab 03 (vnet-N-arm...). Your group may hold at most 10 virtual networks, so clear the old ones first.

The plan

Resource Name Address range
Virtual network hq-vnet 10.40.0.0/16
Subnet apps-subnet 10.40.10.0/24
Subnet data-subnet 10.40.20.0/24
Virtual network warehouse-vnet 10.50.0.0/16
Subnet scanners-subnet 10.50.20.0/24
Subnet tablets-subnet 10.50.21.0/24

Think about it

Why can't the two virtual networks use the same address range if you want to connect them later, as you do in Lab 05?

Task 1: Create a virtual network with subnets

  1. Search for Virtual networks and select + Create.
  2. On Basics:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Name hq-vnet
    Region Southeast Asia
  3. Select Next until you reach IP addresses.

  4. Delete the default address space and the default subnet. Then:
    • Add the address space 10.40.0.0/16.
    • Select + Add a subnet: name apps-subnet, starting address 10.40.10.0, size /24.
    • Add another subnet: name data-subnet, starting address 10.40.20.0, size /24.
  5. Select Review + create, then Create.
  6. Open the virtual network. Under Settings → Subnets, check both subnets.

Reserved addresses

Azure reserves 5 addresses in every subnet. A /24 has 256 addresses, so 251 are usable. The first usable address is .4.

Task 2: Create a virtual network from a template

In Lab 03 you deployed a template. Now you reuse one with parameters to build a second network.

  1. Search for Deploy a custom template and select it.
  2. Select Build your own template in the editor.
  3. Delete everything in the editor and paste this template. Select Save.

    {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "networkName": { "type": "string" },
        "location": { "type": "string", "defaultValue": "southeastasia" },
        "networkRange": { "type": "string" },
        "firstSubnetName": { "type": "string" },
        "firstSubnetRange": { "type": "string" },
        "secondSubnetName": { "type": "string" },
        "secondSubnetRange": { "type": "string" }
      },
      "resources": [
        {
          "type": "Microsoft.Network/virtualNetworks",
          "apiVersion": "2023-09-01",
          "name": "[parameters('networkName')]",
          "location": "[parameters('location')]",
          "properties": {
            "addressSpace": { "addressPrefixes": [ "[parameters('networkRange')]" ] },
            "subnets": [
              { "name": "[parameters('firstSubnetName')]", "properties": { "addressPrefix": "[parameters('firstSubnetRange')]" } },
              { "name": "[parameters('secondSubnetName')]", "properties": { "addressPrefix": "[parameters('secondSubnetRange')]" } }
            ]
          }
        }
      ]
    }
    
  4. Fill in the form:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Network Name warehouse-vnet
    Location southeastasia
    Network Range 10.50.0.0/16
    First Subnet Name scanners-subnet
    First Subnet Range 10.50.20.0/24
    Second Subnet Name tablets-subnet
    Second Subnet Range 10.50.21.0/24
  5. Select Review + create, then Create.

  6. Open warehouse-vnet and check its address space and subnets.

Compare with Task 1

Open hq-vnet → Automation → Export template. If the export is blocked, use your resource group's Deployments → the Task 1 deployment → Template. Which parts of the template changed between the two virtual networks?

Task 3: Create an ASG and an NSG

An application security group names a group of virtual machines, so you can write rules for "the web servers" without listing IP addresses. An NSG holds the rules.

  1. Search for Application security groups and select + Create. Use your resource group, the name asg-webservers, and region Southeast Asia. Create it.
  2. Search for Network security groups and select + Create. Use your resource group, the name nsg-apps, and region Southeast Asia. Create it.
  3. Open nsg-apps. Under Settings, select Subnets → Associate. Choose the virtual network hq-vnet and the subnet apps-subnet. Select OK.

Add an inbound rule

  1. Under Settings, select Inbound security rules. Read the default rules. Note that only other virtual networks and load balancers are allowed in.
  2. Select + Add and set:

    Setting Value
    Source Application security group
    Source application security groups asg-webservers
    Source port ranges *
    Destination Any
    Service Custom
    Destination port ranges 80,443
    Protocol TCP
    Action Allow
    Priority 100
    Name AllowWebServers
  3. Select Add.

Add an outbound rule

  1. Select Outbound security rules. Note the default rule AllowInternetOutBound (priority 65001). You can't delete it, but a rule with a lower number is read first.
  2. Select + Add and set:

    Setting Value
    Source Any
    Source port ranges *
    Destination Service tag
    Destination service tag Internet
    Service Custom
    Destination port ranges *
    Protocol Any
    Action Deny
    Priority 4096
    Name DenyInternetOut
  3. Select Add.

Think about it

  • Rules are read from the lowest number first. Why does DenyInternetOut (4096) win over AllowInternetOutBound (65001)?
  • The ASG isn't attached to any VM yet. What happens when a VM joins asg-webservers later?

Task 4: Create a private DNS zone

A private DNS zone answers name lookups only for the virtual networks linked to it.

  1. Search for Private DNS zones and select + Create.
  2. Use your resource group and the name warehouse.internal. Select Review + create, then Create, and open the zone.
  3. Note that the Overview shows no name servers. Only linked virtual networks can use a private zone.
  4. Under DNS Management, select Virtual network links → + Add:

    Setting Value
    Link name warehouse-link
    Virtual network warehouse-vnet
    Enable auto registration Leave cleared
  5. Select Create. Wait until the link status shows Completed.

  6. Under DNS Management, select Recordsets → + Add:

    Setting Value
    Name scanner01
    Type A
    TTL 1 hour
    IP address 10.50.20.4
  7. Select Add. The full name of the record is scanner01.warehouse.internal.

The public DNS zone

A public zone is not part of this lab. It needs a domain name that you own, so your trainer shows it as a demonstration. The difference: a public zone answers anyone on the internet, a private zone only answers linked virtual networks.

Think about it

10.50.20.4 is in scanners-subnet and is the first usable address. Why is it not 10.50.20.1?

Task 5: Clean up

Delete in this order, so nothing is still in use:

  1. Open nsg-apps and delete it.
  2. Delete asg-webservers.
  3. Delete the private DNS zone warehouse.internal. Azure deletes its link and record with it.
  4. Delete hq-vnet and warehouse-vnet.

Check your work

  • hq-vnet has two subnets, 10.40.10.0/24 and 10.40.20.0/24.
  • warehouse-vnet was created from a template and has scanners-subnet and tablets-subnet.
  • nsg-apps is linked to apps-subnet and has the rules AllowWebServers and DenyInternetOut.
  • The private zone has the link warehouse-link (status Completed) and the record scanner01.
  • Your resource group has none of these resources left.

Key points

  • Plan address ranges so that networks you will connect later don't overlap.
  • Azure reserves 5 addresses per subnet.
  • An NSG filters traffic. Lower priority numbers are read first.
  • An ASG lets you write rules about groups of VMs instead of IP addresses.
  • Private DNS zones resolve names only inside linked virtual networks. Public zones resolve for everyone.