Skip to content

VNet Peering

🎯 Lab Objective

In this hands-on lab, you will learn how to:

  • Understand Azure VNet Peering and its connectivity benefits
  • Create bidirectional VNet peering connections between virtual networks
  • Configure peering settings for different scenarios (gateway transit, forwarded traffic)
  • Test connectivity across peered virtual networks
  • Troubleshoot peering issues and validate configuration
  • Implement hub-and-spoke network topologies using VNet peering

Goal: Establish secure, high-performance connectivity between virtual networks using VNet peering to enable resource communication across network boundaries.


πŸ—οΈ Pre-Provisioned Environment

The following Azure resources have been pre-deployed in your environment:

Resource Overview

Resource TypeResource NameConfigurationPurpose
Resource GroupVNetPeering-Lab-RGContains all lab resourcesLogical container
Hub Virtual NetworkHubVNetAddress space: 10.0.0.0/16Central hub network
Spoke Virtual NetworkSpokeVNetAddress space: 10.1.0.0/16Spoke network
Hub SubnetHubSubnetRange: 10.0.1.0/24Hub resources
Spoke SubnetSpokeSubnetRange: 10.1.1.0/24Spoke resources
Hub VMHubVMWindows Server 2019Hub network server
Spoke VMSpokeVMUbuntu 20.04 LTSSpoke network server

Network Architecture

Before Peering:
β”Œβ”€ HubVNet (10.0.0.0/16) ─┐ β”Œβ”€ SpokeVNet (10.1.0.0/16) ─┐
β”‚ └── HubSubnet β”‚ β”‚ └── SpokeSubnet β”‚
β”‚ └── HubVM β”‚ ❌ β”‚ └── SpokeVM β”‚
β”‚ (10.0.1.4) β”‚ β”‚ (10.1.1.4) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
After Peering:
β”Œβ”€ HubVNet (10.0.0.0/16) ─┐ β”Œβ”€ SpokeVNet (10.1.0.0/16) ─┐
β”‚ └── HubSubnet β”‚ β”‚ └── SpokeSubnet β”‚
β”‚ └── HubVM β”‚ βœ… β”‚ └── SpokeVM β”‚
β”‚ (10.0.1.4) │◄──►│ (10.1.1.4) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

VM Details

VMPrivate IPOperating SystemPurpose
HubVM10.0.1.4Windows Server 2019Hub network testing
SpokeVM10.1.1.4Ubuntu 20.04 LTSSpoke network testing

πŸš€ Lab Exercises

Part 1: Verify Initial Connectivity (Before Peering)

Step 1: Connect to Hub VM

  1. Navigate to VNetPeering-Lab-RG resource group
  2. Click on HubVM
  3. Click Connect β†’ RDP
  4. Use credentials:
    • Username: azureuser
    • Password: LabPassword123!

Step 2: Test Cross-VNet Connectivity

From HubVM, open Command Prompt and test:

Terminal window
# Test connectivity to SpokeVM (should fail)
ping 10.1.1.4
# Test with extended timeout
ping -t 10.1.1.4
# Test port connectivity
telnet 10.1.1.4 22

Expected Results:

  • ❌ Ping to SpokeVM should fail (no route)
  • ❌ All cross-VNet connectivity should be blocked

Step 3: Connect to Spoke VM

  1. Navigate to SpokeVM
  2. Click Connect β†’ SSH
  3. Use Azure Cloud Shell or SSH client:
Terminal window
ssh azureuser@[SpokeVM-Public-IP]
# Password: LabPassword123!

Step 4: Test Reverse Connectivity

From SpokeVM, test connectivity to HubVM:

Terminal window
# Test connectivity to HubVM (should fail)
ping 10.0.1.4
# Test with count limit
ping -c 4 10.0.1.4
# Check routing table
ip route show

Expected Results:

  • ❌ Ping to HubVM should fail
  • ❌ No routes exist for the other VNet

Part 2: Create VNet Peering (Hub to Spoke)

Step 1: Navigate to Hub VNet

  1. Go to VNetPeering-Lab-RG
  2. Click on HubVNet
  3. In the left menu, select Peerings
  4. Click + Add

Step 2: Configure Hub-to-Spoke Peering

Configure the peering connection:

SettingValuePurpose
Peering link nameHubToSpokeConnection identifier
Traffic to remote virtual networkAllowEnable traffic flow
Traffic forwarded from remote virtual networkAllowEnable forwarded traffic
Virtual network gateway or Route ServerNoneNo gateway transit

Step 3: Configure Remote VNet Settings

SettingValuePurpose
Virtual networkSpokeVNetTarget VNet
Peering link nameSpokeToHubRemote connection name
Traffic to remote virtual networkAllowEnable bidirectional traffic
Traffic forwarded from remote virtual networkAllowEnable forwarded traffic
Virtual network gateway or Route ServerNoneNo gateway configuration
  1. Important: Check β€œConfigure remote virtual network peering settings”
  2. Click Add

⏱️ Creation Time: Peering typically establishes within 2-3 minutes.


Part 3: Verify Peering Status

Step 1: Check Peering Status in Hub VNet

  1. In HubVNet, go to Peerings
  2. Verify status: HubToSpoke should show Connected

Step 2: Check Peering Status in Spoke VNet

  1. Navigate to SpokeVNet
  2. Go to Peerings
  3. Verify status: SpokeToHub should show Connected

Step 3: Understand Peering States

StatusMeaningAction Required
ConnectedPeering active and workingNone
InitiatedPeering created, waiting for remoteConfigure remote peering
DisconnectedPeering exists but not functionalCheck configuration

Part 4: Test Cross-VNet Connectivity

Step 1: Test from Hub VM

Return to HubVM RDP session and test:

Terminal window
# Test connectivity to SpokeVM (should now succeed)
ping 10.1.1.4
# Test sustained connectivity
ping -t 10.1.1.4
# Test SSH port (if accessible)
telnet 10.1.1.4 22
# Check routing table
route print

Expected Results:

  • βœ… Ping to SpokeVM should succeed
  • βœ… Low latency (typically less than 1ms within region)
  • βœ… Consistent connectivity

Step 2: Test from Spoke VM

From SpokeVM SSH session:

Terminal window
# Test connectivity to HubVM (should now succeed)
ping 10.0.1.4
# Test with statistics
ping -c 10 10.0.1.4
# Test RDP port
nc -zv 10.0.1.4 3389
# Verify routing
ip route show | grep 10.0

Expected Results:

  • βœ… Ping to HubVM should succeed
  • βœ… Bidirectional connectivity established
  • βœ… Azure routes automatically created

Part 5: Advanced Peering Configuration

Step 1: Test Name Resolution

From HubVM, test hostname resolution:

Terminal window
# Test NetBIOS name resolution (may not work)
ping SpokeVM
# Use nslookup for DNS testing
nslookup SpokeVM
# Test reverse DNS
nslookup 10.1.1.4

Step 2: Configure Custom DNS (Optional)

  1. Go to HubVNet β†’ DNS servers
  2. Configure custom DNS if needed:
    • Custom: Enter DNS server IP
    • Default (Azure-provided): Use Azure DNS

Step 3: Test Performance

From either VM, test network performance:

Terminal window
# Windows (HubVM) - Test with pathping
pathping 10.1.1.4
# Check network utilization
netstat -e
Terminal window
# Linux (SpokeVM) - Test with mtr
sudo apt update && sudo apt install -y mtr-tiny
mtr -c 10 10.0.1.4
# Test bandwidth (if iperf available)
iperf3 -c 10.0.1.4 -t 10

Part 6: Explore Peering Options

Step 1: Modify Peering Settings

  1. Navigate to HubVNet β†’ Peerings
  2. Click on HubToSpoke
  3. Experiment with settings:
SettingOptionsImpact
Allow trafficAllow/BlockControls basic connectivity
Allow forwarded trafficAllow/BlockControls transit routing
Allow gateway transitAllow/BlockEnables gateway sharing
Use remote gatewaysAllow/BlockUses remote VNet gateway

Step 2: Test Setting Changes

  1. Temporarily block traffic:

    • Set β€œTraffic to remote virtual network” to Block
    • Click Save
    • Test connectivity (should fail)
  2. Re-enable traffic:

    • Set back to Allow
    • Click Save
    • Test connectivity (should succeed)

πŸ”§ Troubleshooting Guide

Common Peering Issues and Solutions

IssueSymptomsPossible CauseSolution
Peering shows β€œInitiated”One-way connectivity onlyRemote peering not configuredCreate bidirectional peering
No connectivity despite β€œConnected”Ping failsNSG blocking trafficCheck NSG rules
Partial connectivitySome ports work, others don’tPort-specific blockingReview NSG port rules
High latencySlow response timesCross-region peeringConsider region proximity
Peering creation failsCannot create peeringAddress space overlapEnsure non-overlapping CIDR blocks

Peering Validation Checklist

ComponentCheckExpected Result
Peering StatusBoth VNets show β€œConnectedβ€βœ… Bidirectional connection
Address SpacesNo CIDR overlapβœ… Unique IP ranges
NSG RulesAllow required trafficβœ… Appropriate rules
Route TablesNo conflicting UDRsβœ… Proper routing
Effective RoutesPeering routes presentβœ… Auto-generated routes

πŸ§ͺ Additional Experiments

Try these optional exercises to deepen your understanding:

  1. Hub-and-Spoke Topology: Add a third VNet and create spoke-to-spoke connectivity
  2. Cross-Region Peering: Peer VNets in different Azure regions
  3. Service Chaining: Use peering with network virtual appliances
  4. Gateway Transit: Configure VPN gateway sharing via peering
  5. Global VNet Peering: Test performance across global regions

πŸŽ“ Key Takeaways

After completing this lab, you should understand:

  • VNet Peering enables private connectivity between Azure virtual networks
  • Bidirectional configuration requires peering setup in both VNets
  • Non-overlapping address spaces are required for successful peering
  • Azure automatically creates routes for peered VNet address spaces
  • NSG rules still apply and can block peered traffic
  • Low latency and high bandwidth connectivity within the same region
  • Global VNet Peering enables cross-region connectivity

πŸ“Š VNet Peering vs Alternatives

VNet Peering vs VPN Gateway

FeatureVNet PeeringVPN Gateway
PerformanceHigh bandwidth, low latencyLower bandwidth, higher latency
CostData transfer charges onlyGateway + data transfer charges
EncryptionNo (private Azure backbone)Yes (IPSec encryption)
Setup ComplexitySimpleMore complex
Cross-premisesNoYes

When to Use VNet Peering

  • βœ… High-performance Azure-to-Azure connectivity needed
  • βœ… Cost-effective solution for VNet communication
  • βœ… Simple setup and management preferred
  • βœ… Same tenant connectivity requirements
  • ❌ Not suitable for on-premises connectivity

πŸ“š Additional Resources