Peer two virtual networks
In this task you'll connect two virtual networks with peering.
Each VNet is private by default, so resources in two networks can't reach each other. Peering joins two VNets so they talk over Microsoft's own network on private addresses, as if they were one.
Peering isn't passed along: if A is peered with B and B with C, A still can't reach C unless you peer A and C, or route through a hub.
Example. SS Kaiser keeps shared services, such as its domain controllers, in a hub network, and peers each project's spoke network to the hub. Spokes reach the shared services but not each other.
Costs money. Peering has no hourly charge, but every GB that crosses it is billed in both directions. Two empty test networks with no traffic cost nothing or a few pennies. Delete them straight after.
Before you start
You need: Network Contributor on both networks. Time: 15 minutes.
Where to look
- Virtual networks
- vnet-practice
- Peerings
- + Add
Steps
- Create a second network, vnet-practice-b, in the same resource group with the address space 10.1.0.0/16.The ranges must not overlap, or peering is refused.
- Open vnet-practice, select Peerings, then + Add.
- Name the link from the other side b-to-a, and choose vnet-practice-b as the remote network.
- Name the link from this side a-to-b. Leave Peering type on the standard virtual network peering and the options allowing the networks to reach each other ticked.
- Select Add. The portal creates both directions at once.
- Wait until the peering status shows Connected on both networks.
Commands
# Peering needs a link in each direction
az network vnet peering create --resource-group rg-portal-practice --name a-to-b \
--vnet-name vnet-practice --remote-vnet vnet-practice-b --allow-vnet-access
az network vnet peering create --resource-group rg-portal-practice --name b-to-a \
--vnet-name vnet-practice-b --remote-vnet vnet-practice --allow-vnet-access
Watch out for
- Cost
- Billed per GB of traffic in and out of each side. Peering between regions (global peering) costs more per GB.
- Security
- Peering opens a path between the networks, so check that NSGs still limit which subnets can talk to which.
- Common mistakes
- Overlapping address ranges. Expecting peering to pass through a third network. Creating only one direction with the CLI and wondering why traffic doesn't flow.
Clean up
- Virtual networks
- vnet-practice
- Peerings
Delete the peering, then the second network, or delete the resource group, which removes both networks and the peering together.
Words to know
- Peering
- A private link between two virtual networks.
- Hub and spoke
- A design with one central network for shared services and separate networks for each project.
- Global peering
- Peering between networks in different regions. Traffic costs more than within one region.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On