Overview and What You Will Learn
In this lab, you will create a Site-to-Site VPN Gateway connection, understand the setup and characteristics of ExpressRoute conceptually alongside it, and see why a resilient production hybrid network commonly uses both together rather than choosing only one.
Why This Matters in Production
An enterprise migrating a core banking workload to Azure needs consistent, predictable latency between their on-premises datacenter and Azure - a VPN connection running over the shared public internet cannot guarantee this the way a dedicated physical circuit can. ExpressRoute exists specifically for this requirement, at a meaningfully higher cost and longer provisioning time than a VPN.
Core Principles
VPN Gateway and ExpressRoute both connect an on-premises network to an Azure VNet, but through fundamentally different paths.
+------------------------------------------+| VPN Gateway || Encrypted tunnel over the public internet || Faster and cheaper to set up || Good for backup connectivity or lower || bandwidth needs |+------------------------------------------+| ExpressRoute || Dedicated private physical circuit || Never touches the public internet || Higher bandwidth, more consistent latency || Slower to provision, higher cost |+------------------------------------------+A common, resilient production pattern uses ExpressRoute as the primary connection for its performance and reliability, with a VPN Gateway configured as an automatic backup path if the ExpressRoute circuit ever fails - combining the strengths of both rather than relying on just one.
Detailed Step-by-Step Practical Lab
- Create a Resource Group and a VNet with a dedicated gateway subnet:
az group create --name rg-vpn-lab-mumbai --location centralindia az network vnet create \ --resource-group rg-vpn-lab-mumbai \ --name vnet-vpn-lab \ --address-prefix 10.0.0.0/16 \ --subnet-name subnet-vms \ --subnet-prefix 10.0.1.0/24 az network vnet subnet create \ --resource-group rg-vpn-lab-mumbai \ --vnet-name vnet-vpn-lab \ --name GatewaySubnet \ --address-prefix 10.0.255.0/27NoteThe subnet used for a VPN Gateway must be named exactly
GatewaySubnet- Azure specifically looks for this name when creating the gateway, similar to how Bastion requires its own exact subnet name.
- Create a public IP for the VPN Gateway:
az network public-ip create \ --resource-group rg-vpn-lab-mumbai \ --name pip-vpn-gateway \ --sku Standard \ --allocation-method Static- Create the VPN Gateway itself - this step commonly takes 30-45 minutes to complete, since Azure is provisioning dedicated infrastructure:
az network vnet-gateway create \ --resource-group rg-vpn-lab-mumbai \ --name vpn-gateway-lab \ --public-ip-address pip-vpn-gateway \ --vnet vnet-vpn-lab \ --gateway-type Vpn \ --vpn-type RouteBased \ --sku VpnGw1- Create a Local Network Gateway representing your on-premises network's public IP and address range:
az network local-gateway create \ --resource-group rg-vpn-lab-mumbai \ --name onprem-gateway-lab \ --gateway-ip-address 203.0.113.50 \ --local-address-prefixes 192.168.0.0/16- Create the actual Site-to-Site connection linking the two gateways, using a pre-shared key both sides must match:
az network vpn-connection create \ --resource-group rg-vpn-lab-mumbai \ --name connection-lab \ --vnet-gateway1 vpn-gateway-lab \ --local-gateway2 onprem-gateway-lab \ --shared-key "YourSharedKeyHere2026"- Confirm the connection status once both sides are configured (in a real scenario, your on-premises firewall or router needs matching configuration):
az network vpn-connection show \ --resource-group rg-vpn-lab-mumbai \ --name connection-lab \ --query "connectionStatus" --output tsvExpressRoute is provisioned through a different workflow entirely - working with a connectivity provider to establish the physical circuit, then creating an ExpressRoute Circuit resource in Azure and linking it to your VNet via an ExpressRoute Gateway, a process that commonly takes weeks rather than the minutes-to-an-hour a VPN Gateway requires.
Clean up:
az group delete --name rg-vpn-lab-mumbai --yes --no-waitProduction Best Practices & Common Pitfalls
Common MistakeChoosing VPN Gateway as the sole connectivity method for a workload that genuinely needs the low, consistent latency ExpressRoute provides - like real-time financial trading systems - then discovering internet-path latency variability causes real problems under load.
TipBoth VPN Gateway and ExpressRoute commonly use BGP (Border Gateway Protocol) to exchange routes dynamically between your network and Azure, rather than requiring static routes to be manually maintained on both sides as your network changes over time.
- VPN Gateway is provisioned in minutes to an hour; ExpressRoute takes weeks, since it involves coordinating a physical circuit with a connectivity provider. Plan ExpressRoute provisioning time into any migration timeline well in advance.
- The pre-shared key in a Site-to-Site VPN must match exactly on both the Azure side and the on-premises device. A mismatched key is one of the most common reasons a newly created VPN connection shows as "Not Connected" despite every other setting appearing correct.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az network vnet-gateway create |
Create a VPN Gateway |
az network local-gateway create |
Define the on-premises side of a VPN connection |
az network vpn-connection create |
Create the actual Site-to-Site connection |
az network vpn-connection show --query "connectionStatus" |
Check whether a VPN connection is active |