Configure Virtual Network Peering and Gateway Transit
30-second answer
VNet peering connects two virtual networks so their resources talk on private IPs over the Microsoft backbone, in the same region or across regions (global peering) and even across subscriptions and tenants. A peering is two links, one from each side, and both must show Connected. Address spaces can't overlap. Peering is not transitive: if spoke 1 and spoke 2 are both peered with a hub, they still can't reach each other unless you peer them directly or route through an NVA in the hub. Gateway transit lets spokes use the hub's VPN or ExpressRoute gateway: set allow gateway transit on the hub's link and use remote gateways on the spoke's link.
Simulate it » No Azure account neededExam objective: 4.1.2 Create and configure virtual network peering. (Skills measured as of April 17, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Open <strong>vnet-hub → Settings → Peerings</strong>. The hub already has a VPN gateway in its GatewaySubnet.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Open vnet-hub → Settings → Peerings. The hub already has a VPN gateway in its GatewaySubnet.
- Select + Add. One form creates both links.
- The remote section is the spoke's link: it may receive forwarded traffic and uses the hub's gateway. The local section is the hub's link: it allows gateway transit.
- Both links show Connected. Repeat for spoke 2. Spokes now reach on-premises through the hub gateway.
- From the spoke you only see the hub. To link spokes, peer them directly or route through an NVA in the hub with user-defined routes.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Peering is not transitive
VNet peering joins two VNets over the Microsoft backbone. Each side has its own link, address spaces can't overlap, and the hub can share its VPN gateway (gateway transit). Peering never chains: spoke 1 and spoke 2 can't talk through the hub on their own.
🤔 What happens if…
Read this tour as text
- VNets, subnets and a public IP. A virtual network is your private range in one region, split into subnets. Azure keeps 5 addresses in every subnet. A Standard public IP is static, zone-redundant where the region has zones, and closed to inbound traffic until an NSG opens it.
- Peering is not transitive. VNet peering joins two VNets over the Microsoft backbone. Each side has its own link, address spaces can't overlap, and the hub can share its VPN gateway (gateway transit). Peering never chains: spoke 1 and spoke 2 can't talk through the hub on their own.
- User-defined routes to the NVA. A route table on a subnet overrides system routes. Next hop Virtual appliance sends traffic to a firewall or NVA, which needs IP forwarding on its NIC. Longest prefix wins, and a user route beats a system route on the same prefix.
- NSGs, ASGs and effective rules. An NSG has rules checked by priority (100 to 4096, lowest first). Inbound traffic meets the subnet NSG first, then the NIC NSG, and both must allow. An application security group lets a rule say "to the web servers" instead of listing IPs.
- Azure Bastion. Azure Bastion lives in AzureBastionSubnet (/26 or larger) and opens RDP and SSH to VMs on their private IPs, from the portal over TLS 443 or with the native client on Standard and Premium. One Bastion in the hub serves peered spokes.
- Service endpoint vs private endpoint. A service endpoint sends a subnet's traffic to the service's public IP over the backbone, and the service firewall allows that subnet. A private endpoint gives the service a private IP in your VNet, and a privatelink private DNS zone makes the name resolve to it.
- Azure DNS: public and private zones. A public zone answers the internet once you delegate the domain to Azure's name servers. Alias records point at Azure resources such as a public IP. A private zone answers only VNets with a virtual network link, and can auto-register VM names.
- Standard load balancer and health probes. A load balancer spreads TCP/UDP flows from a frontend (public or internal) to a backend pool by load-balancing rules. A health probe pulls a VM out of rotation when it stops answering. Probes come from 168.63.129.16.
- Troubleshoot with Network Watcher. Network Watcher tools answer one question each. IP flow verify: which NSG rule allows or denies this flow? Next hop: where does this packet go? Connection troubleshoot: can A reach B, and if not, at which hop?
Contoso wants one hub VNet for shared services and two spoke VNets for apps. Build the address plan, give the hub a static public IP and a VPN gateway, peer everything, then find out the hard way that spoke 1 can't talk to spoke 2 until you route it through a firewall in the hub.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Each team has its own VNet and its own VPN gateway, and the bill shows it.
😊 THE SOLUTION
Peer the spokes to a hub and let them share the hub gateway with gateway transit.
- One gateway per VNet✓ Gateway transit from the hub
- Traffic over the internet✓ Private backbone peering
- Spokes can't reach each other✓ Peer directly or route via the hub NVA
Start with a question
If you're friends with Priya and Priya is friends with Sam, are you friends with Sam?
Not automatically. You might meet Sam at Priya’s party, but you don’t have Sam’s number. You’d have to swap numbers yourself, or ask Priya to pass messages along.
VNet peering works the same way. Peer spoke 1 with the hub and spoke 2 with the hub, and each spoke can talk to the hub. The spokes still can’t talk to each other, because peering isn’t transitive. They need their own peering, or the hub has to pass the messages on.
Explain it like I’m 10
The technical explanation
What a peering is
A peering connects two VNets so they route to each other directly. Traffic stays private and on Microsoft’s backbone, latency is like being in one network, and there’s no gateway in the path. It works:
- In the same region (regional peering) or across regions (global peering).
- Across subscriptions and across Microsoft Entra tenants (you need permissions on both VNets, such as Network Contributor).
Each side has its own link. One side alone shows Initiated; when both exist, both show Connected. If one side is deleted, the other shows Disconnected and you recreate it.
Rules to remember:
- Address spaces can’t overlap.
- Peering is not transitive.
- NSGs still apply. The default rule AllowVnetInBound covers peered VNets, because the VirtualNetwork tag includes peered address spaces.
- You pay per GB in and out of each side; global peering costs more (around $0.01 to $0.035 per GB, illustrative).
Peering settings
| Setting (portal wording, simplified) | What it does |
|---|---|
| Allow A to access B | Lets traffic flow at all. On by default. |
| Allow A to receive forwarded traffic from B | Accepts packets that didn’t start in B, for example forwarded by an NVA in the hub. |
| Allow gateway or route server in A to forward traffic to B | Allow gateway transit on the side that has the gateway (the hub). |
| Enable A to use B’s remote gateway or route server | Use remote gateways on the side without a gateway (the spoke). |
For gateway transit, the hub needs a VPN or ExpressRoute gateway, the spoke can’t have its own, and the hub link must allow transit before the spoke link can use remote gateways.
Hub and spoke
Shared services (firewall, VPN gateway, Bastion, DNS) live in the hub. Each workload gets a spoke peered to the hub. Spoke-to-spoke traffic goes through the hub firewall using user-defined routes, or you peer specific spokes directly. Azure Virtual Network Manager can create these topologies for many VNets at once.
-
1 Plan
Hub 10.0.0.0/16, spoke 10.1.0.0/16. No overlap.
-
2 Hub link
hub-to-spoke1: allow access, allow gateway transit.
-
3 Spoke link
spoke1-to-hub: allow access, allow forwarded traffic, use remote gateways.
-
4 Connected
Both links Connected. The spoke reaches the hub and on-premises.
Portal and CLI
Portal: vnet-hub → Settings → Peerings → + Add. One form creates both links.
az network vnet peering create -g rg-net-hub -n hub-to-spoke1 \
--vnet-name vnet-hub --remote-vnet vnet-spoke1 --allow-vnet-access --allow-gateway-transit
az network vnet peering create -g rg-net-hub -n spoke1-to-hub \
--vnet-name vnet-spoke1 --remote-vnet vnet-hub --allow-vnet-access \
--allow-forwarded-traffic --use-remote-gateways
az network vnet peering list -g rg-net-hub --vnet-name vnet-hub -o table
For a remote VNet in another resource group or subscription, pass its full resource ID to --remote-vnet. In PowerShell it’s Add-AzVirtualNetworkPeering (once per side), with -AllowGatewayTransit and -UseRemoteGateways.
Architect level Changing address space on a peered VNet
You can add or resize address ranges on a VNet that’s already peered. After the change the peering shows it’s out of sync, and you run Sync on the remote side (portal button or az network vnet peering sync) so the other VNet learns the new range. You no longer need to delete and recreate the peering.
Real-world business scenario
Northwind Logistics (fictional)
- The problem
- Four app teams each ran their own VPN gateway to the head office, paying for four gateways around the clock, and the warehouse app couldn't reach the billing app at all.
- What they used
- A hub VNet with one VPN gateway and an Azure Firewall. Each team's VNet became a spoke peered to the hub with gateway transit (hub) and use remote gateways (spoke). Route tables on the spokes send spoke-to-spoke traffic to the firewall.
- Why that choice
- One gateway serves every spoke, and the firewall becomes the single place to allow or log traffic between apps.
- The result
- Three gateways were deleted, and warehouse to billing traffic now flows through the firewall with a rule the security team can read.
When to use it and when not to
✓ Use it when…
- Two or more Azure VNets need private, low-latency connectivity, in the same or different regions.
- A hub and spoke design where spokes share a gateway, firewall or Bastion.
- Connecting VNets that belong to different subscriptions or tenants.
✕ Think twice when…
- VNets whose address spaces overlap. Re-address one first.
- Expecting the hub to pass traffic between spokes without routes and an NVA.
- Huge meshes managed by hand. Use Azure Virtual Network Manager or Virtual WAN.
↔ Alternatives to consider
- VNet-to-VNet VPN when you need encryption by a gateway or IPsec specifically.
- Azure Virtual WAN for large, transitive hub designs managed by Microsoft.
- Azure Virtual Network Manager to build hub and spoke or mesh connectivity at scale.
Test yourself with exercises
5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What does VNet peering give you that a VPN between two VNets doesn't?
Model answer
Peering doesn't need gateways at all. The VNets route to each other directly on Microsoft's backbone, with low latency and no bandwidth limit from a gateway SKU. You pay per GB in and out, but there's no hourly gateway charge.
Intermediate Your peering shows Initiated. What's wrong?
Model answer
Only one side has been created. A peering is two links, so I create the link from the other VNet back to the first one. In the portal one form creates both; with the CLI I run az network vnet peering create twice. Then both show Connected.
Experienced developer How do spokes reach on-premises through a hub VPN gateway?
Model answer
On the hub's peering to each spoke I enable allow gateway transit. On each spoke's peering to the hub I enable use remote gateways. The hub must already have the gateway, and the spoke can't have its own. Then the spokes learn the on-premises routes and the hub gateway advertises the spoke ranges.
Scenario Spoke 1 and spoke 2 are both peered to the hub, but VMs in spoke 1 can't ping spoke 2. Fix it.
Model answer
Peering isn't transitive, so that's expected. I can peer the two spokes directly, or keep hub and spoke and put a firewall or NVA in the hub. For the NVA route I add a route table on each spoke subnet sending the other spoke's range to the NVA, turn on IP forwarding on the NVA NIC, and allow forwarded traffic on the spoke peerings.
Quick revision
Key points
- Peering = two links, both must be Connected. Works across regions, subscriptions and tenants.
- Address spaces can't overlap. Traffic stays private on the Microsoft backbone.
- Peering is not transitive. Spoke to spoke needs direct peering or a UDR to a hub NVA.
- Gateway transit = allow gateway transit (hub link) + use remote gateways (spoke link).
- Data through a peering is billed per GB in each direction.
Important terminology
- VNet peering
- A connection between two virtual networks that routes traffic between them privately over the Microsoft backbone.
- Global VNet peering
- Peering between VNets in different Azure regions.
- Peering state
- Initiated (only one side exists), Connected (both sides exist) or Disconnected (the other side was deleted).
- Allow forwarded traffic
- A peering setting that accepts traffic that didn't start in the peered VNet, such as packets forwarded by an NVA in the hub.
- Gateway transit
- Letting a peered VNet use this VNet's VPN or ExpressRoute gateway. Allow gateway transit on the hub link, use remote gateways on the spoke link.
- Non-transitive
- Peering A-B and B-C doesn't connect A and C.
Common mistakes
- Creating only one side and wondering why traffic doesn't flow.
- Assuming the hub forwards traffic between spokes on its own.
- Enabling use remote gateways on a spoke that has its own gateway, or before the hub has one.
Exam tips
- "VNet1 peered to VNet2, VNet2 peered to VNet3, can VNet1 reach VNet3?" = No.
- "Spokes must use the hub VPN gateway" = allow gateway transit on hub + use remote gateways on spokes.
- "Peering fails to create" = check for overlapping address spaces.
Five quick revision questions
-
1.How many peering links connect two VNets?Show
Two, one in each direction.
-
2.Can peered VNets have overlapping address spaces?Show
No.
-
3.Is global peering allowed across subscriptions?Show
Yes, and across Microsoft Entra tenants too.
-
4.Which setting goes on the spoke for gateway transit?Show
Use remote gateways.
-
5.Which setting lets traffic from a hub NVA into a spoke?Show
Allow forwarded traffic on the spoke's peering.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: User-Defined Routes and Route Tables
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.