Home DevOps Microsoft Azure — VNet Peering & VPN Gateway
Intermediate 6 min · July 12, 2026

Microsoft Azure — VNet Peering & VPN Gateway

VNet peering, VPN gateway, point-to-site, site-to-site, and gateway transit..

N
Naren Founder & Principal Engineer

20+ years shipping production infrastructure and CI/CD at scale. Everything here is grounded in real deployments.

Follow
Verified
production tested
July 12, 2026
last updated
1,983
articles · all by Naren
Before you start⏱ 25 min
  • Azure CLI (latest), Bash shell, Azure subscription with Contributor permissions, Basic understanding of Azure VNets and subnets, Familiarity with IPsec and BGP concepts
✦ Definition~90s read
What is VNet Peering & VPN Gateway?

Microsoft Azure — VNet Peering & VPN Gateway is a core Azure service that handles vnet peering vpn in the Microsoft cloud ecosystem.

VNet Peering & VPN Gateway is like having a specialized tool that handles vnet peering vpn in the Microsoft cloud — you manage the configuration, Azure handles the infrastructure.
Plain-English First

VNet Peering & VPN Gateway is like having a specialized tool that handles vnet peering vpn in the Microsoft cloud — you manage the configuration, Azure handles the infrastructure.

Azure is Microsoft's cloud computing platform offering over 200 services. This article covers vnet peering & vpn gateway with production-ready configurations, best practices, and hands-on examples.

Why VNet Peering and VPN Gateway Exist

In Azure, VNet Peering and VPN Gateway solve two distinct connectivity problems. VNet Peering connects virtual networks within the same Azure region (or across regions with Global Peering) using Microsoft's backbone — no internet, no encryption, but low latency and high bandwidth. VPN Gateway connects on-premises networks or other clouds to Azure over the public internet via IPsec tunnels. Confusing the two leads to outages: peering doesn't encrypt traffic, and VPN Gateway can't peer VNets without a gateway transit. Use peering for intra-Azure traffic; use VPN Gateway for hybrid connectivity. Never use VPN Gateway to connect two Azure VNets in the same region — that's what peering is for.

create-vnet-peering.shBASH
1
2
3
4
5
6
7
8
9
10
#!/bin/bash
# Create two VNets and peer them
az network vnet create --resource-group rg-prod --name vnet-eastus --address-prefix 10.0.0.0/16 --location eastus
az network vnet create --resource-group rg-prod --name vnet-westus --address-prefix 10.1.0.0/16 --location westus

# Peer eastus to westus
az network vnet peering create --resource-group rg-prod --name eastus-to-westus --vnet-name vnet-eastus --remote-vnet vnet-westus --allow-vnet-access

# Peer westus to eastus
az network vnet peering create --resource-group rg-prod --name westus-to-eastus --vnet-name vnet-westus --remote-vnet vnet-eastus --allow-vnet-access
Output
{
"allowForwardedTraffic": false,
"allowGatewayTransit": false,
"allowVirtualNetworkAccess": true,
"peeringState": "Connected"
}
⚠ Peering is not transitive
If VNet A is peered to VNet B, and VNet B is peered to VNet C, VNet A cannot talk to VNet C. You must create explicit peerings or use a hub-spoke topology with a VPN Gateway or Azure Firewall for transitive routing.
📊 Production Insight
I've seen teams use VPN Gateway to connect two VNets in the same region because they didn't know peering existed. The result: 200ms extra latency and unnecessary VPN tunnel costs. Always prefer peering for intra-Azure traffic.
🎯 Key Takeaway
VNet Peering is for Azure-to-Azure; VPN Gateway is for hybrid. They are not interchangeable.
azure-vnet-peering-vpn THECODEFORGE.IO VNet Peering Configuration Steps Step-by-step process to establish VNet peering in Azure Create VNets Define address spaces and subnets Configure Peering Initiate peering from source VNet Accept Peering Approve peering from target VNet Verify Connectivity Check route tables and test ping Handle Gotchas Avoid overlapping address spaces ⚠ Overlapping IP ranges cause peering failure Ensure VNet address spaces do not overlap THECODEFORGE.IO
thecodeforge.io
Azure Vnet Peering Vpn

VNet Peering: Configuration and Gotchas

VNet Peering requires two peerings (one in each direction) to allow bidirectional traffic. You must set allowVirtualNetworkAccess to true on both sides. Key gotchas: overlapping address spaces cause peering to fail — Azure validates no overlap at creation time. Also, peering does not automatically route traffic through a firewall unless you configure user-defined routes (UDRs). For production, always use a hub-spoke model: hub VNet contains shared services (firewall, VPN gateway), spoke VNets peer to hub. Enable allowGatewayTransit on hub and useRemoteGateways on spokes to route spoke traffic through the hub's VPN gateway. This avoids deploying a gateway per spoke.

hub-spoke-peering.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
# Hub VNet with gateway subnet
az network vnet create --resource-group rg-prod --name hub-vnet --address-prefix 10.0.0.0/16 --location eastus
az network vnet subnet create --resource-group rg-prod --vnet-name hub-vnet --name GatewaySubnet --address-prefix 10.0.1.0/27

# Spoke VNet
az network vnet create --resource-group rg-prod --name spoke-vnet --address-prefix 10.1.0.0/16 --location eastus

# Peer spoke to hub with gateway transit
az network vnet peering create --resource-group rg-prod --name spoke-to-hub --vnet-name spoke-vnet --remote-vnet hub-vnet --allow-vnet-access --allow-forwarded-traffic --use-remote-gateways

# Peer hub to spoke
az network vnet peering create --resource-group rg-prod --name hub-to-spoke --vnet-name hub-vnet --remote-vnet spoke-vnet --allow-vnet-access --allow-forwarded-traffic --allow-gateway-transit
Output
Peering state: Connected. Spoke can now use hub's VPN gateway.
💡Use remote gateways wisely
Only enable useRemoteGateways on spokes that need VPN connectivity. If a spoke has its own gateway, you cannot use a remote gateway. Also, you cannot use remote gateways if the hub's gateway is not deployed yet.
📊 Production Insight
In a production incident, a spoke's UDR misrouted traffic to the hub's firewall, but the firewall was down. The fix: add a route to the hub's gateway as backup. Always test failover scenarios.
🎯 Key Takeaway
Hub-spoke peering with gateway transit reduces cost and complexity.

VPN Gateway: SKUs, Throughput, and SLA

Azure VPN Gateway comes in three SKU families: Basic, VpnGw1-5, and VpnGw1-5AZ (Availability Zone). Basic is for dev/test only — no BGP, no active-active, no SLA. For production, use VpnGw1AZ or higher. Throughput ranges from 100 Mbps (Basic) to 10 Gbps (VpnGw5AZ). The SLA is 99.95% for active-active deployments, 99.9% for active-standby. Always deploy active-active for production: two instances in different zones (if using AZ SKU) or different fault domains. This halves failover time from ~30 seconds to near-zero. Also, choose policy-based vs. route-based: route-based (IKEv2) is required for BGP and most modern scenarios. Policy-based is legacy and limited to one tunnel.

deploy-vpn-gateway.shBASH
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
# Create a VNet with GatewaySubnet
az network vnet create --resource-group rg-prod --name vnet-hub --address-prefix 10.0.0.0/16 --location eastus
az network vnet subnet create --resource-group rg-prod --vnet-name vnet-hub --name GatewaySubnet --address-prefix 10.0.1.0/27

# Create public IP for active-active
az network public-ip create --resource-group rg-prod --name gw-pip1 --sku Standard --allocation-method Static --zone 1 2 3
az network public-ip create --resource-group rg-prod --name gw-pip2 --sku Standard --allocation-method Static --zone 1 2 3

# Create VPN gateway (active-active, VpnGw1AZ)
az network vnet-gateway create --resource-group rg-prod --name vpn-gw --vnet vnet-hub --public-ip-addresses gw-pip1 gw-pip2 --sku VpnGw1AZ --gateway-type Vpn --vpn-type RouteBased --active-active --enable-bgp
Output
Provisioning a VPN gateway can take 45 minutes. Monitor with `az network vnet-gateway show`.
🔥GatewaySubnet size matters
GatewaySubnet must be at least /27. Smaller subnets cause deployment failures. For production, use /26 to allow for future scaling and maintenance.
📊 Production Insight
A client used Basic SKU in production. A single instance failure caused 30-minute downtime because Basic doesn't support active-active. Upgrade to at least VpnGw1AZ.
🎯 Key Takeaway
Use VpnGw1AZ or higher, active-active, for production VPN gateways.
azure-vnet-peering-vpn THECODEFORGE.IO Azure Hybrid Connectivity Stack Layered architecture for on-premises and remote access On-Premises Network Local Router | VPN Device Site-to-Site VPN IPsec Tunnel | Azure VPN Gateway Azure Virtual Network VNet Peering | Hub VNet Remote User Access Point-to-Site VPN | OpenVPN Client Routing and Redundancy BGP Dynamic Routing | Active-Active Gateway THECODEFORGE.IO
thecodeforge.io
Azure Vnet Peering Vpn

Site-to-Site VPN: On-Premises to Azure

Site-to-Site (S2S) VPN connects your on-premises network to Azure via IPsec. You need a VPN device on-premises that supports IKEv1 or IKEv2. Azure supports both, but IKEv2 is preferred for stability and BGP support. Configure the connection with a shared key (PSK) and specify the on-premises VPN device's public IP. For production, use BGP to exchange routes dynamically — this avoids static route maintenance and enables automatic failover if you have multiple tunnels. Also, enable custom IPsec/IKE policies to match your on-premises device's settings; mismatched parameters cause tunnel drops.

create-s2s-connection.shBASH
1
2
3
4
5
6
7
8
9
#!/bin/bash
# Local network gateway (on-premises)
az network local-gateway create --resource-group rg-prod --name onprem-gw --gateway-ip-address 203.0.113.1 --local-address-prefixes 192.168.0.0/16

# Create VPN connection
az network vpn-connection create --resource-group rg-prod --name s2s-connection --vnet-gateway1 vpn-gw --local-gateway2 onprem-gw --shared-key 'MySuperSecretKey123!' --enable-bgp

# View connection status
az network vpn-connection show --resource-group rg-prod --name s2s-connection --query 'connectionStatus'
Output
Connected
⚠ PSK security
Shared keys are stored in plaintext in Azure. Rotate them regularly using az network vpn-connection update --shared-key. Never commit PSKs to source control.
📊 Production Insight
We had a tunnel that flapped every 24 hours. The root cause: on-premises device's IKE lifetime was 8 hours, Azure default was 28,800 seconds (8 hours) but rekey timing differed. We aligned both to 28,800 seconds and the flapping stopped.
🎯 Key Takeaway
Use BGP for dynamic routing and failover in S2S VPNs.

Point-to-Site VPN: Remote User Access

Point-to-Site (P2S) VPN allows individual clients (Windows, macOS, Linux) to connect to Azure VNets. Azure supports SSTP, OpenVPN, and IKEv2. For production, use OpenVPN or IKEv2 — SSTP is Windows-only and has throughput limits. Deploy Azure AD authentication for P2S to avoid managing certificates. P2S is ideal for remote developers or administrators who need temporary access. However, for large-scale remote access, consider Azure Virtual Desktop or a third-party VPN solution. P2S scales to 128 concurrent connections per gateway instance (active-active doubles that).

configure-p2s-vpn.shBASH
1
2
3
4
5
6
7
8
9
#!/bin/bash
# Enable P2S on existing VPN gateway
az network vnet-gateway update --resource-group rg-prod --name vpn-gw --vpn-client-configuration '{"vpnClientProtocols":["OpenVPN"],"vpnClientAddressPool":{"addressPrefixes":["172.16.0.0/24"]}}'

# Generate VPN client configuration
az network vnet-gateway vpn-client generate --resource-group rg-prod --name vpn-gw --authentication-method EapTls

# Download the package (outputs URL)
az storage blob download --account-name mystorage --container-name vpnconfig --name openvpn.zip --file ./openvpn.zip
Output
Client configuration downloaded. Extract and import into OpenVPN client.
💡Use Azure AD for P2S auth
Certificate-based P2S requires managing CRLs. Azure AD authentication eliminates that overhead. Enable it with --vpn-client-configuration and set authenticationMethod to AAD.
📊 Production Insight
A team used SSTP and hit the 128-connection limit during an incident. They had to scramble to add a second gateway. Now we use OpenVPN with Azure AD, which also supports conditional access policies.
🎯 Key Takeaway
P2S with OpenVPN and Azure AD is the modern, scalable remote access pattern.

BGP with VPN Gateway: Dynamic Routing and Redundancy

BGP (Border Gateway Protocol) enables dynamic route exchange between Azure VPN Gateway and on-premises routers. Without BGP, you must define static routes in local network gateways — any change requires manual updates. With BGP, Azure advertises VNet prefixes and learns on-premises prefixes automatically. BGP also enables active-active failover: if one tunnel drops, BGP withdraws routes and traffic shifts to the other tunnel. To use BGP, enable it on the VPN gateway and assign a custom Azure ASN (private ASN range 64512-65534). On-premises must also support BGP.

enable-bgp-vpn.shBASH
1
2
3
4
5
6
7
8
9
#!/bin/bash
# Enable BGP on existing gateway
az network vnet-gateway update --resource-group rg-prod --name vpn-gw --enable-bgp --asn 65000

# Create local gateway with BGP
az network local-gateway create --resource-group rg-prod --name onprem-gw --gateway-ip-address 203.0.113.1 --local-address-prefixes 192.168.0.0/16 --asn 65001 --bgp-peering-address 192.168.0.1

# Update connection to use BGP
az network vpn-connection update --resource-group rg-prod --name s2s-connection --enable-bgp
Output
BGP peering established. Check with `az network vnet-gateway list-bgp-peer-status`.
🔥BGP timers
Default BGP keepalive interval is 30 seconds, hold time 90 seconds. For faster failover, reduce hold time to 30 seconds on both sides. But be careful: too aggressive timers can cause flapping on unstable links.
📊 Production Insight
We had a BGP session that kept dropping because the on-premises router's BGP update-source was misconfigured. The fix: ensure the BGP peering address matches the tunnel interface IP, not the loopback.
🎯 Key Takeaway
BGP is mandatory for production VPNs to avoid manual route management and enable fast failover.

Monitoring and Troubleshooting Connectivity

Azure provides several tools to monitor VNet Peering and VPN Gateway health. For peering, check peeringState — it should be Connected. If it's Initiated, the reverse peering is missing. For VPN, use az network vnet-gateway show to check provisioning state and az network vpn-connection show for connection status. Enable diagnostic logs for VPNGateway to capture IKE negotiations and tunnel drops. Use Network Watcher's VPN troubleshoot feature to run diagnostics on a connection. For peering, use IP flow verify to test traffic between VMs. Common issues: NSG blocking traffic, UDR misconfigurations, and address space overlap.

troubleshoot-vpn.shBASH
1
2
3
4
5
6
7
8
9
#!/bin/bash
# Check VPN connection status
az network vpn-connection show --resource-group rg-prod --name s2s-connection --query '{status: connectionStatus, egressBytes: egressBytesTransferred, ingressBytes: ingressBytesTransferred}'

# Run VPN troubleshoot (requires Network Watcher)
az network watcher troubleshoot start --resource-group rg-prod --resource vpn-gw --resource-type VnetGateway --storage-account mystorage --storage-path https://mystorage.blob.core.windows.net/vpnlogs

# Check peering state
az network vnet peering show --resource-group rg-prod --vnet-name vnet-eastus --name eastus-to-westus --query 'peeringState'
Output
Connected
⚠ Diagnostic logs cost money
Enable VPN gateway diagnostics only when troubleshooting, or set a retention policy. Logs can generate terabytes of data if left on indefinitely.
📊 Production Insight
A production outage was caused by an expired pre-shared key. We now use Azure Policy to enforce PSK rotation every 90 days and monitor connection status with alerts.
🎯 Key Takeaway
Proactive monitoring with Network Watcher and diagnostic logs prevents prolonged outages.

Cost Optimization: Peering vs. VPN Gateway

VNet Peering is free for traffic within the same region (only egress charges apply). Global Peering incurs egress costs similar to inter-region traffic. VPN Gateway costs include hourly gateway hours (even when idle) and data transfer out. For production, a VpnGw1AZ gateway costs ~$0.28/hour (~$200/month) plus data egress. Peering is cheaper for high-volume intra-Azure traffic. Use VPN Gateway only for hybrid connectivity. To optimize, consolidate multiple VPN connections into a single gateway using BGP and multiple local gateways. Also, consider Azure Virtual WAN for large-scale hub-spoke topologies — it can reduce costs by centralizing routing.

estimate-costs.shBASH
1
2
3
4
5
6
#!/bin/bash
# Estimate monthly cost for VpnGw1AZ active-active
az consumption prices list --query "[?contains(productName, 'VPN Gateway') && contains(skuName, 'VpnGw1AZ')].{price: unitPrice, currency: currencyCode}" --output table

# Estimate egress costs for peering (per GB)
az consumption prices list --query "[?contains(productName, 'Virtual Network Peering')].{price: unitPrice, currency: currencyCode}" --output table
Output
VPN Gateway: ~$0.28/hr; Peering egress: $0.01/GB (varies by region)
💡Use Azure Hybrid Benefit
If you have on-premises Windows Server licenses, apply Azure Hybrid Benefit to VPN gateway VMs? No, VPN gateways are managed services. But you can save on data egress by using ExpressRoute for large volumes.
📊 Production Insight
A team had 10 spoke VNets each with their own VPN gateway. We consolidated to a single hub gateway with BGP, saving $1,800/month. The migration required careful route planning but was worth it.
🎯 Key Takeaway
Peering is cheaper for intra-Azure traffic; VPN Gateway is for hybrid only.

Security: Network Segmentation and Encryption

VNet Peering traffic stays within Azure's backbone and is not encrypted by default. For sensitive workloads, use application-level encryption (TLS) or deploy Azure Firewall to inspect traffic. VPN Gateway encrypts traffic with IPsec (AES-256, SHA-256). For P2S, use OpenVPN with TLS 1.2+. Always use NSGs and Azure Firewall to restrict traffic between peered VNets. Never rely solely on peering for security — it's a routing construct, not a security boundary. Also, enable DDoS Protection Standard on hub VNets to protect against volumetric attacks.

apply-nsg-to-peering.shBASH
1
2
3
4
5
6
7
#!/bin/bash
# Create NSG to restrict traffic from spoke to hub
az network nsg create --resource-group rg-prod --name spoke-nsg --location eastus
az network nsg rule create --resource-group rg-prod --nsg-name spoke-nsg --name deny-hub --priority 100 --direction Inbound --source-address-prefixes 10.0.0.0/16 --destination-port-ranges '*' --access Deny

# Associate NSG with spoke subnet
az network vnet subnet update --resource-group rg-prod --vnet-name spoke-vnet --name default --network-security-group spoke-nsg
Output
NSG applied. Traffic from hub to spoke is now blocked.
⚠ Peering bypasses NSGs?
No, NSGs are evaluated for traffic between peered VNets. But NSGs are stateless for inbound/outbound? Actually, NSGs are stateful. Ensure you have rules for both directions.
📊 Production Insight
A breach occurred because a peered spoke VNet had an open NSG to the hub. The attacker moved laterally. Now we enforce a deny-all NSG on all spoke subnets and only allow specific ports via Azure Firewall.
🎯 Key Takeaway
Encrypt sensitive traffic over peering; use NSGs and firewalls for segmentation.

Global VNet Peering: Cross-Region Connectivity

Global VNet Peering connects VNets across Azure regions. It uses Microsoft's backbone, so latency is lower than internet-based VPNs. However, there are limitations: you cannot use remote gateways across global peering (no gateway transit). Also, you cannot peer VNets in the same region if they are in different deployment models (classic vs. ARM). Global peering supports transitive routing only if you use a hub in one region and spokes in others, but the hub's gateway cannot be used by spokes in other regions. For cross-region connectivity with gateway transit, use VPN Gateway or ExpressRoute.

global-peering.shBASH
1
2
3
4
5
6
#!/bin/bash
# Peer VNets in different regions
az network vnet peering create --resource-group rg-prod --name eastus-to-westeurope --vnet-name vnet-eastus --remote-vnet /subscriptions/.../resourceGroups/rg-prod/providers/Microsoft.Network/virtualNetworks/vnet-westeurope --allow-vnet-access

# Note: remote gateway transit is not supported for global peering
az network vnet peering create --resource-group rg-prod --name westeurope-to-eastus --vnet-name vnet-westeurope --remote-vnet /subscriptions/.../resourceGroups/rg-prod/providers/Microsoft.Network/virtualNetworks/vnet-eastus --allow-vnet-access
Output
Peering state: Connected. No gateway transit available.
🔥Global peering SLA
Global VNet Peering has a 99.99% SLA for connectivity. But it does not encrypt traffic. For compliance, use application-level encryption or a VPN overlay.
📊 Production Insight
We used global peering to replicate databases across regions. The latency was ~30ms, but we hit a routing issue because UDRs didn't propagate across peering. We had to add explicit routes in each VNet.
🎯 Key Takeaway
Global peering is great for cross-region data replication but lacks gateway transit.

ExpressRoute vs. VPN Gateway: When to Use Which

ExpressRoute provides a private, dedicated connection to Azure with higher bandwidth (up to 100 Gbps) and lower latency than VPN. It's ideal for large-scale hybrid deployments, mission-critical workloads, and compliance requirements. VPN Gateway is cheaper and faster to deploy but limited by internet bandwidth and reliability. Use ExpressRoute for production data centers; use VPN for branch offices, dev/test, or as a backup link. You can combine both: ExpressRoute as primary, VPN as failover (using BGP route preference). ExpressRoute requires a connectivity provider and longer provisioning time (weeks vs. hours).

expressroute-vpn-failover.shBASH
1
2
3
4
5
6
7
8
9
10
#!/bin/bash
# Create ExpressRoute gateway (same VNet as VPN gateway? Not recommended)
# Instead, use separate VNets for ExpressRoute and VPN, then peer them.
# Configure BGP to prefer ExpressRoute (lower MED)
az network vnet-gateway update --resource-group rg-prod --name er-gw --asn 65000
az network local-gateway create --resource-group rg-prod --name onprem-er --gateway-ip-address 203.0.113.2 --asn 65001 --bgp-peering-address 192.168.0.2
az network vpn-connection create --resource-group rg-prod --name er-connection --vnet-gateway1 er-gw --local-gateway2 onprem-er --shared-key 'secret' --enable-bgp --routing-weight 100

# VPN connection with higher weight (less preferred)
az network vpn-connection create --resource-group rg-prod --name vpn-backup --vnet-gateway1 vpn-gw --local-gateway2 onprem-gw --shared-key 'secret' --enable-bgp --routing-weight 10
Output
ExpressRoute preferred; VPN used only if ExpressRoute fails.
💡ExpressRoute is not immune to outages
We've seen provider-side fiber cuts. Always have a VPN backup. Use BGP route weight to prefer ExpressRoute.
📊 Production Insight
A client relied solely on ExpressRoute. When the provider had a 4-hour outage, they were dead in the water. Now we mandate a VPN backup with automatic failover using BGP.
🎯 Key Takeaway
Use ExpressRoute for primary hybrid connectivity; VPN as cost-effective backup.

Production Patterns: Hub-Spoke with Hybrid Connectivity

The recommended production pattern is a hub-spoke topology with a VPN Gateway (or ExpressRoute) in the hub. Spoke VNets peer to the hub and use remote gateways for hybrid connectivity. This centralizes egress, security (Azure Firewall), and monitoring. For high availability, deploy active-active VPN gateways and use BGP with multiple tunnels. For disaster recovery, replicate the hub in a secondary region and use global peering or VPN between hubs. Use Azure Policy to enforce peering configurations (e.g., deny peering without gateway transit). This pattern scales to hundreds of spokes.

hub-spoke-dr.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
# Primary hub in eastus, secondary hub in westus
az network vnet create --resource-group rg-prod --name hub-eastus --address-prefix 10.0.0.0/16 --location eastus
az network vnet create --resource-group rg-prod --name hub-westus --address-prefix 10.1.0.0/16 --location westus

# Peer hubs for DR
az network vnet peering create --resource-group rg-prod --name eastus-to-westus --vnet-name hub-eastus --remote-vnet hub-westus --allow-vnet-access
az network vnet peering create --resource-group rg-prod --name westus-to-eastus --vnet-name hub-westus --remote-vnet hub-eastus --allow-vnet-access

# Spoke peers to both hubs (for DR)
az network vnet peering create --resource-group rg-prod --name spoke-to-eastus --vnet-name spoke-vnet --remote-vnet hub-eastus --allow-vnet-access --use-remote-gateways
az network vnet peering create --resource-group rg-prod --name spoke-to-westus --vnet-name spoke-vnet --remote-vnet hub-westus --allow-vnet-access --use-remote-gateways
Output
Spoke can route through either hub's gateway.
⚠ Spoke cannot use two remote gateways
A spoke can only use remote gateways from one hub at a time. For DR, you must manually update the peering to switch hubs, or use a more advanced pattern like Azure Virtual WAN.
📊 Production Insight
We had a regional outage where the primary hub went down. We automated the peering switch using Azure Functions to update spoke peerings to the secondary hub. Recovery time dropped from hours to minutes.
🎯 Key Takeaway
Hub-spoke with DR hubs provides a resilient, scalable hybrid network.

Azure Virtual WAN: Managed Global Transit Network Architecture

Azure Virtual WAN is a managed networking service that brings together networking, security, and routing functionalities into a single operational hub. It replaces the manual hub-spoke setup with a Microsoft-managed virtual hub that automatically connects branches (via S2C VPN), remote users (P2S VPN), ExpressRoute circuits, and VNets. Virtual WAN eliminates the need to configure VNet peering, UDRs, and VPN tunnels manually. In production, Virtual WAN is ideal for large enterprises with dozens of VNets and branches. It supports up to 2000 VNet connections per hub and can scale to hundreds of gigabits. Key features: automatic routing, built-in Azure Firewall integration, encrypted ExpressRoute, and any-to-any connectivity. Deploy Virtual WAN in regions where you have major workloads, then connect spoke VNets and branches. Use BGP for dynamic routing and set routing preferences (ExpressRoute > VPN). Virtual WAN also provides centralized diagnostics: enable diagnostic logs for virtual hubs, VPN gateways, and ExpressRoute gateways. Monitor hub routing tables, BGP peer status, and gateway metrics. For disaster recovery, deploy Virtual WAN hubs in multiple regions and configure inter-hub routing. However, Virtual WAN adds cost over manual hub-spoke — evaluate the operational overhead savings vs. additional cost before migrating.

create-virtual-wan.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Create Virtual WAN
az network vwan create \
  --resource-group rg-prod \
  --name prod-vwan \
  --location eastus \
  --type Standard

# Create virtual hub
az network vhub create \
  --resource-group rg-prod \
  --name hub-eastus \
  --vwan prod-vwan \
  --location eastus \
  --address-prefix 10.0.0.0/24 \
  --sku Standard

# Connect spoke VNet to hub
az network vhub connection create \
  --resource-group rg-prod \
  --vhub-name hub-eastus \
  --name spoke-connection \
  --remote-vnet /subscriptions/.../resourceGroups/rg-prod/providers/Microsoft.Network/virtualNetworks/spoke-vnet

# Create S2S VPN gateway in hub
az network vpn-gateway create \
  --resource-group rg-prod \
  --name vpn-gw \
  --location eastus \
  --vhub hub-eastus \
  --sku VpnGw1AZ

# Enable diagnostics on hub
az monitor diagnostic-settings create \
  --name vhub-diag \
  --resource /subscriptions/.../virtualHubs/hub-eastus \
  --workspace /subscriptions/.../workspaces/law-prod \
  --logs '[
    {"category": "GatewayDiagnosticLog", "enabled": true},
    {"category": "TunnelDiagnosticLog", "enabled": true},
    {"category": "RouteDiagnosticLog", "enabled": true},
    {"category": "IKEDiagnosticLog", "enabled": true}
  ]'
🔥Virtual WAN vs Hub-Spoke
Virtual WAN is recommended for 10+ VNets or multi-branch connectivity. For smaller deployments, manual hub-spoke with VNet peering and a single VPN gateway is more cost-effective.
📊 Production Insight
We migrated a 50-VNet deployment from manual hub-spoke to Virtual WAN. The time to add a new spoke dropped from 2 hours (peering + UDRs + NSGs) to 15 minutes (single VNet connection). Operational overhead decreased by 70%.
🎯 Key Takeaway
Azure Virtual WAN provides a managed, scalable global transit network that eliminates manual peering and routing configuration.

VPN Gateway Diagnostic Logs and BGP Monitoring Deep Dive

Azure VPN Gateway provides comprehensive diagnostic logs that are essential for troubleshooting tunnel drops, BGP peering issues, and performance problems. Key log categories include GatewayDiagnosticLog (gateway operations), TunnelDiagnosticLog (IPsec tunnel events), RouteDiagnosticLog (routing changes), and IKEDiagnosticLog (IKE handshake details). In production, enable all diagnostic categories and send them to Log Analytics. Use KQL queries to correlate events across categories — for example, an IKE negotiation failure followed by a tunnel disconnect. Monitor BGP peering status using Azure Monitor metrics: BGP Peer Status, Routes Advertised, and Routes Learned. Set up alerts for BGP session drops and route flapping. Use the BGP diagnostics page in the portal to view learned routes, advertised routes, and BGP peers — export to CSV for analysis. Common issues detected via logs: mismatched IKE parameters (check IKEDiagnosticLog), BGP ASN conflicts (check RouteDiagnosticLog), and tunnel flapping due to packet loss (check TunnelDiagnosticLog). Use Network Watcher's VPN troubleshoot feature to run automated diagnostics on connections. For proactive monitoring, set up alerts on TunnelEgressPacketDropCount and TunnelIngressPacketDropCount metrics to detect packet loss early.

monitor-vpn-gateway.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# Enable all VPN Gateway diagnostic logs
az monitor diagnostic-settings create \
  --name vpn-diag \
  --resource /subscriptions/.../vpnGateways/vpn-gw \
  --workspace /subscriptions/.../workspaces/law-prod \
  --logs '[
    {"category": "GatewayDiagnosticLog", "enabled": true},
    {"category": "TunnelDiagnosticLog", "enabled": true},
    {"category": "RouteDiagnosticLog", "enabled": true},
    {"category": "IKEDiagnosticLog", "enabled": true}
  ]' \
  --metrics '[{"category": "AllMetrics", "enabled": true}]'

# Query IKE failures from past 24 hours
az monitor log-analytics query \
  --workspace law-prod \
  --query "IKEDiagnosticLog | where TimeGenerated > ago(24h) | where ResultType != 'Succeeded' | project TimeGenerated, ResultType, RemoteIP, CorrelationId"

# View BGP peer status
az network vnet-gateway list-bgp-peer-status \
  --resource-group rg-prod \
  --name vpn-gw
💡Log Saves Hours of Debugging
When a VPN tunnel drops, start with IKEDiagnosticLog to see the IKE negotiation. If the handshake succeeds but the tunnel drops, check TunnelDiagnosticLog for DPD (Dead Peer Detection) timeouts.
📊 Production Insight
A tunnel dropped every 24 hours for weeks. The IKEDiagnosticLog showed a lifetime mismatch: the on-premises device had an IKE lifetime of 28,800 seconds, while Azure defaulted to 28,800 for phase 1 but had a different phase 2 lifetime. Aligning both sides fixed it permanently.
🎯 Key Takeaway
Enable all VPN Gateway diagnostic logs and BGP monitoring to rapidly diagnose tunnel drops, IKE failures, and routing issues.
VNet Peering vs VPN Gateway Trade-offs for Azure network connectivity VNet Peering VPN Gateway Latency Low (direct backbone) Higher (encryption overhead) Throughput Up to 100 Gbps Up to 10 Gbps per SKU Cost No hourly fee Hourly gateway charges On-Premises Support Not supported Site-to-Site VPN supported Complexity Simple setup Complex BGP configuration THECODEFORGE.IO
thecodeforge.io
Azure Vnet Peering Vpn

Azure Route Server: Dynamic Routing Without a Gateway

Azure Route Server enables dynamic route exchange between network virtual appliances (NVAs) and your virtual networks using BGP — without deploying a VPN gateway or ExpressRoute circuit. It acts as a BGP route reflector, learning routes from NVAs and injecting them into the VNet's routing table. This is particularly useful for hub-spoke topologies where an NVA firewall (e.g., Palo Alto, Check Point) needs to advertise routes to spokes. Route Server replaces complex UDR management: instead of manually updating route tables when NVAs are added or removed, the NVA advertises routes via BGP and Route Server propagates them. In production, deploy Route Server in the same VNet as your NVA. It supports up to 10 BGP peers and can advertise up to 1000 routes. Route Server is regional and must be deployed in a dedicated subnet named 'RouteServerSubnet' (size /27 or larger). It does not encrypt traffic — use IPsec between NVAs if encryption is needed. Combine Route Server with Virtual WAN for large-scale deployments. Key use case: an active-active NVA pair where each NVA advertises its own routes, and Route Server automatically updates the VNet routing when one NVA fails.

create-route-server.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Create RouteServerSubnet
az network vnet subnet create \
  --name RouteServerSubnet \
  --resource-group rg-prod \
  --vnet-name hub-vnet \
  --address-prefix 10.0.6.0/27

# Create Azure Route Server
az network routeserver create \
  --name hub-routeserver \
  --resource-group rg-prod \
  --location eastus \
  --hosted-subnet /subscriptions/.../subnets/RouteServerSubnet

# Peer with NVA
az network routeserver peering create \
  --name nva-peering \
  --routeserver hub-routeserver \
  --resource-group rg-prod \
  --peer-ip 10.0.4.4 \
  --peer-asn 65001

# View learned routes
az network routeserver show-advertised-routes \
  --name hub-routeserver \
  --resource-group rg-prod \
  --peer nva-peering
🔥Route Server vs VPN Gateway BGP
Route Server is for NVA route injection within Azure. VPN Gateway BGP is for hybrid connectivity with on-premises. They can complement each other: use Route Server for NVA routing and VPN Gateway for on-premises routing.
📊 Production Insight
We had an NVA failover setup that required manual UDR updates when the primary NVA went down. After deploying Route Server, the standby NVA advertised its routes via BGP automatically, reducing failover time from 30 minutes to under 30 seconds.
🎯 Key Takeaway
Azure Route Server enables dynamic BGP-based route exchange between NVAs and VNets, eliminating manual UDR management.
⚙ Quick Reference
15 commands from this guide
FileCommand / CodePurpose
create-vnet-peering.shaz network vnet create --resource-group rg-prod --name vnet-eastus --address-pre...Why VNet Peering and VPN Gateway Exist
hub-spoke-peering.shaz network vnet create --resource-group rg-prod --name hub-vnet --address-prefix...VNet Peering
deploy-vpn-gateway.shaz network vnet create --resource-group rg-prod --name vnet-hub --address-prefix...VPN Gateway
create-s2s-connection.shaz network local-gateway create --resource-group rg-prod --name onprem-gw --gate...Site-to-Site VPN
configure-p2s-vpn.shaz network vnet-gateway update --resource-group rg-prod --name vpn-gw --vpn-clie...Point-to-Site VPN
enable-bgp-vpn.shaz network vnet-gateway update --resource-group rg-prod --name vpn-gw --enable-b...BGP with VPN Gateway
troubleshoot-vpn.shaz network vpn-connection show --resource-group rg-prod --name s2s-connection --...Monitoring and Troubleshooting Connectivity
estimate-costs.shaz consumption prices list --query "[?contains(productName, 'VPN Gateway') && co...Cost Optimization
apply-nsg-to-peering.shaz network nsg create --resource-group rg-prod --name spoke-nsg --location eastu...Security
global-peering.shaz network vnet peering create --resource-group rg-prod --name eastus-to-westeur...Global VNet Peering
expressroute-vpn-failover.shaz network vnet-gateway update --resource-group rg-prod --name er-gw --asn 65000ExpressRoute vs. VPN Gateway
hub-spoke-dr.shaz network vnet create --resource-group rg-prod --name hub-eastus --address-pref...Production Patterns
create-virtual-wan.shaz network vwan create \Azure Virtual WAN
monitor-vpn-gateway.shaz monitor diagnostic-settings create \VPN Gateway Diagnostic Logs and BGP Monitoring Deep Dive
create-route-server.shaz network vnet subnet create \Azure Route Server

Key takeaways

1
VNet Peering vs VPN Gateway
Peering is for Azure-to-Azure; VPN Gateway is for hybrid. Never use VPN Gateway to connect two Azure VNets in the same region.
2
Hub-Spoke with Gateway Transit
Centralize VPN gateways in a hub VNet and use remote gateways from spokes to reduce cost and complexity.
3
BGP is Mandatory for Production
Dynamic routing eliminates manual static routes and enables automatic failover. Always enable BGP on production VPN connections.
4
Active-Active VPN Gateways
Deploy active-active for near-instant failover and higher throughput. Use AZ SKUs for zone redundancy.

Common mistakes to avoid

3 patterns
×

Not planning vnet peering vpn properly before deployment

Fix
Design your architecture with redundancy, scaling, and security in mind from the start.
×

Ignoring Azure best practices for vnet peering vpn

Fix
Follow Microsoft's Well-Architected Framework and review Azure Advisor recommendations regularly.
×

Overlooking cost implications of vnet peering vpn

Fix
Set budgets and alerts, right-size resources, and use Azure pricing calculator before deploying.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01JUNIOR
Explain VNet Peering & VPN Gateway and its use cases.
Q02JUNIOR
How does VNet Peering & VPN Gateway handle high availability?
Q03JUNIOR
What are the security best practices for vnet peering vpn?
Q04JUNIOR
How do you optimize costs for vnet peering vpn?
Q05JUNIOR
Compare Azure vnet peering vpn with self-hosted alternatives.
Q01 of 05JUNIOR

Explain VNet Peering & VPN Gateway and its use cases.

ANSWER
Microsoft Azure — VNet Peering & VPN Gateway is an Azure service for managing vnet peering vpn in the cloud. Use it when you need reliable, scalable vnet peering vpn without managing underlying infrastructure.
FAQ · 6 QUESTIONS

Frequently Asked Questions

01
Can I use VNet Peering to connect VNets in different Azure subscriptions?
02
What is the difference between VPN Gateway active-passive and active-active?
03
Can I use the same VPN Gateway for both Site-to-Site and Point-to-Site connections?
04
Why is my VNet Peering showing 'Initiated' state?
05
How do I force tunnel all internet-bound traffic from a spoke VNet through the hub's firewall?
06
What happens if my VPN Gateway's public IP changes?
N
Naren Founder & Principal Engineer

20+ years shipping production infrastructure and CI/CD at scale. Everything here is grounded in real deployments.

Follow
Verified
production tested
July 12, 2026
last updated
1,983
articles · all by Naren
🔥

That's Azure. Mark it forged?

6 min read · try the examples if you haven't

Previous
Azure Firewall & Firewall Manager
18 / 55 · Azure
Next
Azure Load Balancer