Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 33 of 47
❮Prev Next❯

Configure Virtual Network Peering and Gateway Transit

Module 4: Networking ⏱ 11 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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 needed

    Exam 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.

    Azure portal: Peer a spoke with the hub and share its VPN gateway Peer a spoke with the hub and share the hub gateway.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    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
    1. Open vnet-hub → Settings → Peerings. The hub already has a VPN gateway in its GatewaySubnet.
    2. Select + Add. One form creates both links.
    3. 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.
    4. Both links show Connected. Repeat for spoke 2. Spokes now reach on-premises through the hub gateway.
    5. 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.

    😟 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
    🛠️ Solved with: VNet peering

    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 BLets traffic flow at all. On by default.
    Allow A to receive forwarded traffic from BAccepts 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 BAllow gateway transit on the side that has the gateway (the hub).
    Enable A to use B’s remote gateway or route serverUse 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. 1 Plan

      Hub 10.0.0.0/16, spoke 10.1.0.0/16. No overlap.

    2. 2 Hub link

      hub-to-spoke1: allow access, allow gateway transit.

    3. 3 Spoke link

      spoke1-to-hub: allow access, allow forwarded traffic, use remote gateways.

    4. 4 Connected

      Both links Connected. The spoke reaches the hub and on-premises.

    Peering a spoke to a hub that has a VPN gateway

    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

    Logistics

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    VNet1 is peered with VNet2. VNet2 is peered with VNet3. No other peerings or routes exist. Which statement is true?

    Question 2

    Question 2 of 5

    You create a peering from VNet1 to VNet2. The peering status shows Initiated. What should you do?

    Question 3

    Question 3 of 5 · Select 2

    A hub virtual network contains a VPN gateway that connects to the on-premises network. A spoke virtual network is peered with the hub. Resources in the spoke must reach the on-premises network through the hub gateway. Which two settings should you configure? Each correct answer presents part of the solution.

    Question 4

    Question 4 of 5

    You attempt to create a peering between VNet1 (10.0.0.0/16) and VNet2 (10.0.128.0/17). The operation fails. What is the cause?

    Question 5

    Question 5 of 5

    A network virtual appliance (NVA) in a hub virtual network forwards traffic from Spoke1 to Spoke2. Spoke2 drops the forwarded traffic. Routes and IP forwarding are configured correctly. What should you configure?

    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. 1.How many peering links connect two VNets?Show

      Two, one in each direction.

    2. 2.Can peered VNets have overlapping address spaces?Show

      No.

    3. 3.Is global peering allowed across subscriptions?Show

      Yes, and across Microsoft Entra tenants too.

    4. 4.Which setting goes on the spoke for gateway transit?Show

      Use remote gateways.

    5. 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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.