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.
π Please sign in to launch lab.
ποΈ Pre-Provisioned Environment
The following Azure resources have been pre-deployed in your environment:
Resource Overview
Resource Type | Resource Name | Configuration | Purpose |
---|---|---|---|
Resource Group | VNetPeering-Lab-RG | Contains all lab resources | Logical container |
Hub Virtual Network | HubVNet | Address space: 10.0.0.0/16 | Central hub network |
Spoke Virtual Network | SpokeVNet | Address space: 10.1.0.0/16 | Spoke network |
Hub Subnet | HubSubnet | Range: 10.0.1.0/24 | Hub resources |
Spoke Subnet | SpokeSubnet | Range: 10.1.1.0/24 | Spoke resources |
Hub VM | HubVM | Windows Server 2019 | Hub network server |
Spoke VM | SpokeVM | Ubuntu 20.04 LTS | Spoke 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
VM | Private IP | Operating System | Purpose |
---|---|---|---|
HubVM | 10.0.1.4 | Windows Server 2019 | Hub network testing |
SpokeVM | 10.1.1.4 | Ubuntu 20.04 LTS | Spoke network testing |
π Lab Exercises
Part 1: Verify Initial Connectivity (Before Peering)
Step 1: Connect to Hub VM
- Navigate to VNetPeering-Lab-RG resource group
- Click on HubVM
- Click Connect β RDP
- Use credentials:
- Username:
azureuser
- Password:
LabPassword123!
- Username:
Step 2: Test Cross-VNet Connectivity
From HubVM, open Command Prompt and test:
# Test connectivity to SpokeVM (should fail)ping 10.1.1.4
# Test with extended timeoutping -t 10.1.1.4
# Test port connectivitytelnet 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
- Navigate to SpokeVM
- Click Connect β SSH
- Use Azure Cloud Shell or SSH client:
ssh azureuser@[SpokeVM-Public-IP]# Password: LabPassword123!
Step 4: Test Reverse Connectivity
From SpokeVM, test connectivity to HubVM:
# Test connectivity to HubVM (should fail)ping 10.0.1.4
# Test with count limitping -c 4 10.0.1.4
# Check routing tableip 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
- Go to VNetPeering-Lab-RG
- Click on HubVNet
- In the left menu, select Peerings
- Click + Add
Step 2: Configure Hub-to-Spoke Peering
Configure the peering connection:
Setting | Value | Purpose |
---|---|---|
Peering link name | HubToSpoke | Connection identifier |
Traffic to remote virtual network | Allow | Enable traffic flow |
Traffic forwarded from remote virtual network | Allow | Enable forwarded traffic |
Virtual network gateway or Route Server | None | No gateway transit |
Step 3: Configure Remote VNet Settings
Setting | Value | Purpose |
---|---|---|
Virtual network | SpokeVNet | Target VNet |
Peering link name | SpokeToHub | Remote connection name |
Traffic to remote virtual network | Allow | Enable bidirectional traffic |
Traffic forwarded from remote virtual network | Allow | Enable forwarded traffic |
Virtual network gateway or Route Server | None | No gateway configuration |
- Important: Check βConfigure remote virtual network peering settingsβ
- Click Add
β±οΈ Creation Time: Peering typically establishes within 2-3 minutes.
Part 3: Verify Peering Status
Step 1: Check Peering Status in Hub VNet
- In HubVNet, go to Peerings
- Verify status:
HubToSpoke
should show Connected
Step 2: Check Peering Status in Spoke VNet
- Navigate to SpokeVNet
- Go to Peerings
- Verify status:
SpokeToHub
should show Connected
Step 3: Understand Peering States
Status | Meaning | Action Required |
---|---|---|
Connected | Peering active and working | None |
Initiated | Peering created, waiting for remote | Configure remote peering |
Disconnected | Peering exists but not functional | Check configuration |
Part 4: Test Cross-VNet Connectivity
Step 1: Test from Hub VM
Return to HubVM RDP session and test:
# Test connectivity to SpokeVM (should now succeed)ping 10.1.1.4
# Test sustained connectivityping -t 10.1.1.4
# Test SSH port (if accessible)telnet 10.1.1.4 22
# Check routing tableroute 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:
# Test connectivity to HubVM (should now succeed)ping 10.0.1.4
# Test with statisticsping -c 10 10.0.1.4
# Test RDP portnc -zv 10.0.1.4 3389
# Verify routingip 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:
# Test NetBIOS name resolution (may not work)ping SpokeVM
# Use nslookup for DNS testingnslookup SpokeVM
# Test reverse DNSnslookup 10.1.1.4
Step 2: Configure Custom DNS (Optional)
- Go to HubVNet β DNS servers
- 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:
# Windows (HubVM) - Test with pathpingpathping 10.1.1.4
# Check network utilizationnetstat -e
# Linux (SpokeVM) - Test with mtrsudo apt update && sudo apt install -y mtr-tinymtr -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
- Navigate to HubVNet β Peerings
- Click on HubToSpoke
- Experiment with settings:
Setting | Options | Impact |
---|---|---|
Allow traffic | Allow/Block | Controls basic connectivity |
Allow forwarded traffic | Allow/Block | Controls transit routing |
Allow gateway transit | Allow/Block | Enables gateway sharing |
Use remote gateways | Allow/Block | Uses remote VNet gateway |
Step 2: Test Setting Changes
-
Temporarily block traffic:
- Set βTraffic to remote virtual networkβ to Block
- Click Save
- Test connectivity (should fail)
-
Re-enable traffic:
- Set back to Allow
- Click Save
- Test connectivity (should succeed)
π§ Troubleshooting Guide
Common Peering Issues and Solutions
Issue | Symptoms | Possible Cause | Solution |
---|---|---|---|
Peering shows βInitiatedβ | One-way connectivity only | Remote peering not configured | Create bidirectional peering |
No connectivity despite βConnectedβ | Ping fails | NSG blocking traffic | Check NSG rules |
Partial connectivity | Some ports work, others donβt | Port-specific blocking | Review NSG port rules |
High latency | Slow response times | Cross-region peering | Consider region proximity |
Peering creation fails | Cannot create peering | Address space overlap | Ensure non-overlapping CIDR blocks |
Peering Validation Checklist
Component | Check | Expected Result |
---|---|---|
Peering Status | Both VNets show βConnectedβ | β Bidirectional connection |
Address Spaces | No CIDR overlap | β Unique IP ranges |
NSG Rules | Allow required traffic | β Appropriate rules |
Route Tables | No conflicting UDRs | β Proper routing |
Effective Routes | Peering routes present | β Auto-generated routes |
π§ͺ Additional Experiments
Try these optional exercises to deepen your understanding:
- Hub-and-Spoke Topology: Add a third VNet and create spoke-to-spoke connectivity
- Cross-Region Peering: Peer VNets in different Azure regions
- Service Chaining: Use peering with network virtual appliances
- Gateway Transit: Configure VPN gateway sharing via peering
- 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
Feature | VNet Peering | VPN Gateway |
---|---|---|
Performance | High bandwidth, low latency | Lower bandwidth, higher latency |
Cost | Data transfer charges only | Gateway + data transfer charges |
Encryption | No (private Azure backbone) | Yes (IPSec encryption) |
Setup Complexity | Simple | More complex |
Cross-premises | No | Yes |
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