VNet Peering: Connecting Networks Directly

Connect two Azure Virtual Networks as if they were one โ€” fast, private, and without a gateway
๐ŸŸก Intermediate โฑ 15 Minutes ๐Ÿ“˜ AZ-104 ยท Module 04
Why This Matters

So far you've created isolated VNets with internal routing. But what if you need to connect two separate VNets โ€” maybe one for dev, one for prod? You could route through the internet (slow, insecure), or you could peer them directly (fast, private). VNet peering lets two VNets communicate as if they were one network, without going through a gateway.

Before You Start

PrerequisitesVNets & Subnets, Routing Fundamentals
Time to understand15 minutes
Difficulty๐ŸŸก Intermediate (builds on routing)
What you'll learnHow peering works, regional vs. global, routing considerations, gateway transit

The Simple Idea

What Is VNet Peering?

VNet Peering = A direct, private connection between two Azure Virtual Networks that lets them communicate as if they're part of the same network.

Real-World Analogy: Two Office Buildings Connected by a Bridge

Two separate buildings, each with their own internal phone systems, get a direct bridge connecting them. Employees in Building A can call Building B directly โ€” no need for a gateway or external connection.

Building A (VNet-A: 10.0.0.0/16) โ”‚ โ”œโ”€โ”€ Employees: 10.0.1.0/24 โ”‚ โ””โ”€โ”€ Internal phone system โ”‚ โ””โ”€โ”€ Connection: Direct bridge to Building B (VNet Peering) Building B (VNet-B: 172.16.0.0/16) โ”‚ โ”œโ”€โ”€ Employees: 172.16.1.0/24 โ”‚ โ””โ”€โ”€ Internal phone system โ”‚ โ””โ”€โ”€ Connection: Direct bridge to Building A Result: Employees in Building A can call Building B directly โœ“ No need for a gateway or external connection โœ“

Two Types of Peering

TypeDistanceBandwidthLatencyCost
Regional PeeringSame region (e.g., East US to East US)UnlimitedLowCharged but minimal
Global PeeringDifferent regions (e.g., East US to West Europe)UnlimitedMediumCharged, slightly more

How VNet Peering Works

Step 1: Create Two VNets

VNet-A: 10.0.0.0/16 โ”œโ”€โ”€ Subnet A1: 10.0.1.0/24 โ””โ”€โ”€ Subnet A2: 10.0.2.0/24 VNet-B: 172.16.0.0/16 โ”œโ”€โ”€ Subnet B1: 172.16.1.0/24 โ””โ”€โ”€ Subnet B2: 172.16.2.0/24 Requirement: Address spaces must NOT overlap โœ“

Step 2: Create Peering Connection (Bidirectional)

In Azure Portal: โ”œโ”€ Go to VNet-A โ”œโ”€ Select "Peerings" โ”œโ”€ Add Peering to VNet-B โ”œโ”€ Wait for status: "Connected" โœ“ Behind the scenes: โ”œโ”€ Azure creates routes in both VNets โ”œโ”€ Route to 172.16.0.0/16 โ†’ Peered Network (in VNet-A) โ”œโ”€ Route to 10.0.0.0/16 โ†’ Peered Network (in VNet-B) โ””โ”€ Connection is bidirectional (both directions work automatically) โœ“

Step 3: Subnet Routing After Peering

VNet-A Subnet A1 (10.0.1.0/24) Routing Table: Destination Next Hop Source โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 10.0.0.0/16 Local VNet-A System Route 172.16.0.0/16 Peered VNet-B System Route (AUTO!) 0.0.0.0/0 Internet System Route VM in Subnet A1 wants to reach 172.16.1.5: โ””โ”€ Checks routing table โ””โ”€ Matches: 172.16.0.0/16 โ†’ Peered Network โ””โ”€ Sends traffic directly to peered VNet โœ“

Step 4: NSG Rules Apply

Traffic flows: 10.0.1.5 (VM-A) โ†’ 172.16.1.10 (VM-B) Checks: โ”œโ”€ Routing: Does 172.16.0.0/16 have a route? YES (peering) โœ“ โ”œโ”€ NSG on Subnet A1: Allow outbound? YES (default) โœ“ โ”œโ”€ NSG on Subnet B1: Allow inbound from 10.0.1.0/24? Must be YES โ”‚ โ””โ”€ If NO, connection fails even though peering exists โœ— โ””โ”€ Result: Traffic delivered โœ“ Lesson: Peering allows the route, NSGs still control traffic โœ“

Mental Model: Peering as a Tunnel

Before Peering: VNet-A โ•โ•โ•โ•โ•โ•โ• Internet โ•โ•โ•โ•โ•โ•โ• VNet-B (slow, public, insecure) After Peering: VNet-A โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• VNet-B (direct, private, fast) Inside: Automatic routes direct traffic through the tunnel โœ“ Outside: No internet routing needed โœ“

Regional vs. Global Peering

Regional Peering (Same Region)

Scenario: East US 1 VNet โ†” East US 2 VNet

Configuration: โ”œโ”€ Peering Name: vnet-a-to-vnet-b โ”œโ”€ Peering Type: Regional (same Azure region) โ”œโ”€ Network access: Enabled โ”œโ”€ Traffic forwarding: Can be enabled โ”œโ”€ Virtual network gateway: Optional Performance: โ”œโ”€ Latency: <2ms (very fast) โœ“ โ”œโ”€ Bandwidth: Unlimited โœ“ โ””โ”€ Cost: Charged per GB (ingress only) โœ“ Use case: Dev/Staging/Prod in same region, need to share services

Global Peering (Different Regions)

Scenario: East US VNet โ†” West Europe VNet

Configuration: โ”œโ”€ Peering Name: vnet-a-to-vnet-b-global โ”œโ”€ Peering Type: Global (different regions) โ”œโ”€ Network access: Enabled โ”œโ”€ Traffic forwarding: Can be enabled โ”œโ”€ Virtual network gateway: Optional Performance: โ”œโ”€ Latency: ~100ms (depends on distance) โš  โ”œโ”€ Bandwidth: Unlimited โœ“ โ””โ”€ Cost: Charged per GB (ingress only) โœ“ Use case: Multi-region deployment (US HQ + EU office), replicated services

Worked Example: Real Scenario

The Scenario

TechCorp has:

  • Dev VNet in East US: 10.0.0.0/16
    • Dev App Server: 10.0.1.0/24
    • Dev Database: 10.0.2.0/24
  • Prod VNet in East US: 172.16.0.0/16
    • Prod App Server: 172.16.1.0/24
    • Prod Database: 172.16.2.0/24

Goal: Let Dev and Prod communicate (e.g., backup dev data to prod storage).

Step 1: Create Peering

Azure Portal โ†’ VNet-Dev โ†’ Peerings โ†’ Add Peering name: dev-to-prod VNet: VNet-Prod Wait for status: Connected โœ“ Result: โ”œโ”€ VNet-Dev has new route: 172.16.0.0/16 โ†’ Peered Network โ”œโ”€ VNet-Prod has new route: 10.0.0.0/16 โ†’ Peered Network โ””โ”€ Both VNets can reach each other's subnets โœ“

Step 2: Verify NSG Rules

Dev App Server (10.0.1.10) tries to backup to Prod Storage (172.16.2.20): NSG on Prod Subnet (172.16.2.0/24): Rule: Allow inbound from 10.0.1.0/24 (Dev App subnet) Port: 443 (HTTPS for backup) Action: ALLOW โœ“ Traffic flow: Dev App โ†’ Routing: 172.16.0.0/16 matches peering โ†’ Forward โœ“ โ†’ NSG: Allow from 10.0.1.0/24 on 443 โ†’ Allow โœ“ โ†’ Reaches Prod Storage โœ“

Step 3: Bidirectional Traffic

Prod App Server (172.16.1.10) wants to query Dev Database (10.0.2.5): NSG on Dev Subnet (10.0.2.0/24): Rule: Allow inbound from 172.16.1.0/24 (Prod App subnet) Port: 5432 (PostgreSQL) Action: ALLOW โœ“ Traffic flow: Prod App โ†’ Routing: 10.0.0.0/16 matches peering โ†’ Forward โœ“ โ†’ NSG: Allow from 172.16.1.0/24 on 5432 โ†’ Allow โœ“ โ†’ Reaches Dev Database โœ“ Key: Peering is bidirectional (both directions work automatically) โœ“

Gateway Transit (Advanced)

What Is Gateway Transit?

Gateway Transit = Allow peered VNets to use one VNet's VPN/ExpressRoute gateway.

Use Case: Hub-and-Spoke with Gateway

Hub VNet (10.0.0.0/16) โ”œโ”€โ”€ Has VPN Gateway โ”œโ”€โ”€ On-premises connection: 192.168.0.0/16 โ”‚ โ”œโ”€ Spoke A (10.1.0.0/16) โ€” Peered โ”‚ โ””โ”€โ”€ Needs on-premises access โ”‚ โ””โ”€โ”€ Enable gateway transit โœ“ โ”‚ โ””โ”€ Spoke B (10.2.0.0/16) โ€” Peered โ””โ”€โ”€ Needs on-premises access โ””โ”€โ”€ Enable gateway transit โœ“ Result: Spoke A traffic to on-prem: Spoke A โ†’ Hub Gateway โ†’ VPN โ†’ On-prem โœ“ Spoke B traffic to on-prem: Spoke B โ†’ Hub Gateway โ†’ VPN โ†’ On-prem โœ“ No need for separate gateways in each spoke (cost savings) โœ“

Configuration

When creating peering: โ”œโ”€ Source VNet (Hub): Enable "Allow gateway transit" โ”œโ”€ Target VNet (Spoke): Enable "Use remote gateway" โ””โ”€ Result: Spoke can reach on-premises through Hub's gateway โœ“ Cost benefit: โ”œโ”€ One gateway for entire organization โ”œโ”€ Spokes don't need their own gateways โ””โ”€ Saves money (gateways are expensive) โœ“

Common Mistakes (What NOT to Do)

โŒ Mistake 1: Overlapping Address Spaces

Wrong

VNet-A: 10.0.0.0/16 VNet-B: 10.0.0.0/16 (same address space!) Try to create peering: โ””โ”€ Azure rejects peering โœ— โ””โ”€ Error: "Address space overlaps"

Fix

Make address spaces non-overlapping: โ”œโ”€ VNet-A: 10.0.0.0/16 โœ“ โ”œโ”€ VNet-B: 172.16.0.0/16 โœ“ โ””โ”€ Peering works โœ“

Why it fails: Overlapping addresses cause routing confusion.

โŒ Mistake 2: Forgetting NSG Rules

Wrong

Peering created: VNet-A โ†” VNet-B VM-A (10.0.1.5) tries to reach VM-B (172.16.1.10) Routing works: 172.16.0.0/16 โ†’ Peered VNet โœ“ NSG on VNet-B Subnet: All inbound DENIED โœ— Result: Traffic blocked even though peering exists โœ—

Fix

Add NSG rule on VNet-B: Source: 10.0.1.0/24 (VM-A's subnet) Port: 443 (whatever service needs) Action: ALLOW โœ“ Now traffic flows โœ“

Why it fails: Peering enables the route but doesn't override NSG rules.

โŒ Mistake 3: Not Enabling Traffic Forwarding

Wrong

Scenario: Three VNets, two connected via peering VNet-A โ†” VNet-B (peered) VNet-B โ†” VNet-C (peered) VM in VNet-A tries to reach VNet-C: โ””โ”€ Routing: Does 10.2.0.0/16 (VNet-C) exist in VNet-A? NO โœ— โ””โ”€ VNet-B should forward traffic, but routing not configured โ””โ”€ Result: Connection fails โœ—

Fix

Use custom routing in VNet-A: Destination: 10.2.0.0/16 (VNet-C) Next Hop: VNet-B appliance IP โ””โ”€ Requires VNet-B to enable "forwarded traffic" โœ“ Or use a hub-and-spoke with gateway transit (cleaner) โœ“

Why it fails: Peering doesn't automatically forward between spokes (no transitive routing).

Peering Checklist

โ–ก VNets have non-overlapping address spaces โ””โ”€ Check: Does 10.0.0.0/16 overlap with 172.16.0.0/16? NO โœ“ โ–ก Create peering from both sides (or wait for request) โ””โ”€ VNet-A initiates โ†’ VNet-B accepts โœ“ โ””โ”€ Connection status: Connected โœ“ โ–ก Check routing (automatic system routes created) โ””โ”€ Can VNet-A reach 172.16.0.0/16? Route should exist โœ“ โ–ก Verify NSG rules allow traffic โ””โ”€ NSG on peered VNet allows source/port โœ“ โ–ก Test connectivity โ””โ”€ Ping, SSH, or RDP from VM-A to VM-B โœ“ โ–ก For gateway transit (if needed) โ””โ”€ Hub VNet: "Allow gateway transit" enabled โœ“ โ””โ”€ Spoke VNet: "Use remote gateway" enabled โœ“ โ””โ”€ Routes configured to use hub gateway โœ“

How This Connects to Other Topics

Related to Module 01 (Identity & Governance)

  • RBAC + Peering: Only network admins can create/delete peering
  • Policy: Require peering in hub-and-spoke topology

Related to Module 02 (Storage)

  • Storage Access: Use peering to reach storage in another VNet securely

Related to Module 03 (Compute)

  • VM Communication: VMs in peered VNets can communicate directly

Related to Module 05 (Monitor)

  • Monitor Peering: Check peering metrics (bytes in/out)

See It In Action

Associated labs:

Suggested learning sequence:

  1. โœ… Read VNets & Subnets
  2. โœ… Read Routing Fundamentals
  3. โœ… Read this doc (VNet Peering)
  4. โœ… Work through Lab 15 (hands-on peering setup)
  5. โžก๏ธ Read VPN & ExpressRoute (hybrid connectivity)

Key Takeaways

๐Ÿ’ก Summary
  • Peering = direct connection between VNets (private, fast)
  • Regional peering = same region (low latency, minimal cost)
  • Global peering = different regions (higher latency, higher cost)
  • Peering is bidirectional (both VNets automatically get routes)
  • Routing is automatic (Azure creates system routes)
  • NSG rules still apply (peering enables route, NSGs control traffic)
  • Non-overlapping address spaces required (or peering fails)
  • Gateway transit = spokes use hub's VPN/ExpressRoute gateway (cost savings)

Next Steps

  1. Learn: Read this doc (you're here)
  2. Practice: Lab 15: Configure VNet Peering
  3. Extend: Read VPN & ExpressRoute (connect on-premises)
  4. Design: Hub-and-spoke topology using peering and gateway transit