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.
Before you start¶
- You are signed in to the lab directory (Getting started).
- Your lab resource group is
rg-CLOUD-LAB-GRP-N. ReplaceNwith 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¶
- Search for Virtual networks and select + Create.
-
On Basics:
Setting Value Resource group rg-CLOUD-LAB-GRP-NName hq-vnetRegion Southeast Asia -
Select Next until you reach IP addresses.
- 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 address10.40.10.0, size/24. - Add another subnet: name
data-subnet, starting address10.40.20.0, size/24.
- Add the address space
- Select Review + create, then Create.
- 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.
- Search for Deploy a custom template and select it.
- Select Build your own template in the editor.
-
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')]" } } ] } } ] } -
Fill in the form:
Setting Value Resource group rg-CLOUD-LAB-GRP-NNetwork Name warehouse-vnetLocation southeastasiaNetwork Range 10.50.0.0/16First Subnet Name scanners-subnetFirst Subnet Range 10.50.20.0/24Second Subnet Name tablets-subnetSecond Subnet Range 10.50.21.0/24 -
Select Review + create, then Create.
- Open
warehouse-vnetand 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.
- Search for Application security groups and select + Create. Use your resource group, the name
asg-webservers, and region Southeast Asia. Create it. - Search for Network security groups and select + Create. Use your resource group, the name
nsg-apps, and region Southeast Asia. Create it. - Open
nsg-apps. Under Settings, select Subnets → Associate. Choose the virtual networkhq-vnetand the subnetapps-subnet. Select OK.
Add an inbound rule¶
- Under Settings, select Inbound security rules. Read the default rules. Note that only other virtual networks and load balancers are allowed in.
-
Select + Add and set:
Setting Value Source Application security group Source application security groups asg-webserversSource port ranges *Destination Any Service Custom Destination port ranges 80,443Protocol TCP Action Allow Priority 100Name AllowWebServers -
Select Add.
Add an outbound rule¶
- 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. -
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 4096Name DenyInternetOut -
Select Add.
Think about it
- Rules are read from the lowest number first. Why does
DenyInternetOut(4096) win overAllowInternetOutBound(65001)? - The ASG isn't attached to any VM yet. What happens when a VM joins
asg-webserverslater?
Task 4: Create a private DNS zone¶
A private DNS zone answers name lookups only for the virtual networks linked to it.
- Search for Private DNS zones and select + Create.
- Use your resource group and the name
warehouse.internal. Select Review + create, then Create, and open the zone. - Note that the Overview shows no name servers. Only linked virtual networks can use a private zone.
-
Under DNS Management, select Virtual network links → + Add:
Setting Value Link name warehouse-linkVirtual network warehouse-vnetEnable auto registration Leave cleared -
Select Create. Wait until the link status shows Completed.
-
Under DNS Management, select Recordsets → + Add:
Setting Value Name scanner01Type A TTL 1hourIP address 10.50.20.4 -
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:
- Open
nsg-appsand delete it. - Delete
asg-webservers. - Delete the private DNS zone
warehouse.internal. Azure deletes its link and record with it. - Delete
hq-vnetandwarehouse-vnet.
Check your work¶
-
hq-vnethas two subnets,10.40.10.0/24and10.40.20.0/24. -
warehouse-vnetwas created from a template and hasscanners-subnetandtablets-subnet. -
nsg-appsis linked toapps-subnetand has the rulesAllowWebServersandDenyInternetOut. - The private zone has the link
warehouse-link(status Completed) and the recordscanner01. - 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.