Connect Azure Networks: VNet Peering, User-Defined Routes, VPN Gateway, ExpressRoute and Virtual WAN
VNet Peering
- Connects two VNets over the Microsoft backbone with low latency. Works across regions (global peering) and subscriptions
- Peering is not transitive: A-B and B-C does not give A-C
- Address spaces must not overlap
- Create a peering in both directions
bash
az network vnet peering create -g rg-net -n hub-to-spoke --vnet-name vnet-hub --remote-vnet vnet-spoke --allow-vnet-access --allow-forwarded-traffic --allow-gateway-transit
az network vnet peering create -g rg-net -n spoke-to-hub --vnet-name vnet-spoke --remote-vnet vnet-hub --allow-vnet-access --allow-forwarded-traffic --use-remote-gateways
az network vnet peering list -g rg-net --vnet-name vnet-hub -o table
- Allow gateway transit (hub) and Use remote gateways (spoke) let spokes use the hub's VPN gateway
Routing
- Azure creates system routes for VNet, internet and peering automatically
- A user-defined route (UDR) in a route table overrides them, for example to send traffic to a firewall
- Next hop types: Virtual appliance, Virtual network gateway, VNet, Internet, None
- Associate a route table with a subnet
bash
az network route-table create -g rg-net -n rt-spoke
az network route-table route create -g rg-net --route-table-name rt-spoke -n to-firewall --address-prefix 0.0.0.0/0 \
--next-hop-type VirtualAppliance --next-hop-ip-address 10.0.1.4
az network vnet subnet update -g rg-net --vnet-name vnet-spoke -n web --route-table rt-spoke
VPN Gateway
| Type | Use |
|---|---|
| Site-to-site (S2S) | IPsec tunnel between your office or datacenter VPN device and Azure |
| Point-to-site (P2S) | One user or admin connects from a laptop |
| VNet-to-VNet | Between VNets (peering is simpler and faster) |
- Create a GatewaySubnet (/27)
- Create a Standard public IP and the VPN gateway (takes 30 to 45 minutes)
- Create a local network gateway representing your on-premises device and address ranges
- Create the connection with a shared key
- Configure your on-premises device and verify the tunnel is Connected
bash
az network vnet-gateway create -g rg-net -n vpngw --vnet vnet-hub --public-ip-addresses pip-vpngw --gateway-type Vpn --vpn-type RouteBased --sku VpnGw1 --no-wait
az network local-gateway create -g rg-net -n lgw-office --gateway-ip-address 203.0.113.10 --local-address-prefixes 192.168.0.0/24
az network vpn-connection create -g rg-net -n conn-office --vnet-gateway1 vpngw --local-gateway2 lgw-office --shared-key '<SharedKey>'
- Use active-active and zone-redundant gateways for higher availability
- BGP gives dynamic routing
- P2S supports OpenVPN, IKEv2 and Entra ID sign-in
ExpressRoute
- A private connection through a connectivity provider, not over the internet
- More predictable latency and higher bandwidth than VPN
- A circuit needs a provider, bandwidth and peering type: private peering (VNets) and Microsoft peering (Microsoft 365 and public Azure endpoints)
- Plan redundancy: two connections, or ExpressRoute plus VPN backup
Virtual WAN
A managed service that connects many branches, VNets and users through virtual hubs with built-in VPN, ExpressRoute and routing. Good for large, multi-region networks.
Troubleshooting Connectivity
| Tool | Use |
|---|---|
| Network Watcher Connection troubleshoot | Test reachability between two endpoints |
| IP flow verify / NSG diagnostics | Which NSG rule blocks |
| Next hop | Where traffic goes from a VM |
| Effective routes | Routes applied to a NIC |
| VPN diagnostics | Gateway logs and tunnel state |
Practice
- Create two VNets and peer them in both directions
- Ping a VM across the peering using private IPs
- Add a UDR that sends internet traffic to a virtual appliance IP
- Draw the steps of a site-to-site VPN
Conclusion
Peering links VNets with low latency (not transitive). UDRs control paths. VPN gateways and ExpressRoute connect on-premises, and Network Watcher helps troubleshoot routes and rules.
Quick Summary: peering; routing; VPN; ExpressRoute; Virtual WAN; troubleshooting.

