VNet Peering and Service Endpoints
Connect two VNets using VNet peering for low-latency private communication, and use service endpoints to route traffic to Azure services without the public internet.
VNet Peering and Service Endpoints is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Need for VNet Peering
Resources in different Azure VNets cannot communicate with each other by default — even if they are in the same Azure region. However, large organisations often have multiple VNets: separate VNets for development, staging, and production, or different VNets for different departments. VNet Peering connects two VNets directly through Microsoft's private backbone network, enabling resources in both VNets to communicate as if they were in the same network — without any traffic traversing the public internet or requiring a VPN gateway.
How VNet Peering Works
VNet Peering is a non-transitive connection: if VNet A is peered with VNet B, and VNet B is peered with VNet C, VNet A cannot communicate with VNet C unless you create a separate peering between A and C. Peering links are bidirectional but must be configured on both sides — creating a peering from A to B does not automatically create one from B to A. Once both sides are configured, traffic between the peered VNets uses the Azure backbone with low latency and high bandwidth, comparable to inter-subnet communication within a single VNet.
# Create peering from VNet-A to VNet-B
az network vnet peering create \
--resource-group myRG \
--name A-to-B \
--vnet-name VNet-A \
--remote-vnet VNet-B \
--allow-vnet-access
# Create return peering from VNet-B to VNet-A
az network vnet peering create \
--resource-group myRG \
--name B-to-A \
--vnet-name VNet-B \
--remote-vnet VNet-A \
--allow-vnet-accessLocal vs Global Peering
VNet Peering has two scope options: Local VNet Peering connects two VNets in the same Azure region. Traffic stays within the region and incurs a small per-GB transfer fee. Global VNet Peering connects two VNets in different Azure regions, routed over Microsoft's global backbone. This enables resources in East US to communicate privately with resources in West Europe without traversing the public internet. Global peering has a slightly higher transfer cost than local peering, but is still significantly cheaper and more reliable than routing through a VPN.
Hub-and-Spoke with Peering
A common enterprise pattern uses VNet Peering to implement a hub-and-spoke topology. A central hub VNet hosts shared services: Azure Firewall, VPN Gateway, DNS servers, and monitoring. Multiple spoke VNets (one per environment or workload) peer with the hub. By routing all spoke traffic through the hub firewall, the organisation gets centralised security inspection without complex NSG management in each spoke. Since peering is non-transitive, the hub firewall routes traffic between spokes using User-Defined Routes (UDRs).
Address Space Requirements for Peering
VNet Peering has one critical requirement: the address spaces of peered VNets must not overlap. If VNet A uses 10.0.0.0/16 and VNet B also uses 10.0.0.0/16, peering fails because Azure cannot route traffic between identical address ranges. This is why planning non-overlapping CIDR ranges for all VNets — and for on-premises networks — before you begin is so important. Changing a VNet's address space after resources are deployed requires recreating the VNet or using the (limited) address space add/remove feature.
What Are Service Endpoints?
Service Endpoints extend the VNet's identity to Azure PaaS services like Azure Storage, Azure SQL Database, Azure Key Vault, and Cosmos DB. When you enable a service endpoint on a subnet, traffic from resources in that subnet to the specified Azure service is routed over the Azure backbone rather than the public internet — even though the service's public IP address is used. The service can then restrict access to only resources within VNets that have the service endpoint enabled, providing a significant security improvement over internet-accessible endpoints.
# Enable Service Endpoint for Storage on a subnet
az network vnet subnet update \
--resource-group myRG \
--vnet-name myVNet \
--name app-tier \
--service-endpoints Microsoft.StorageService Endpoints vs Private Endpoints
Service Endpoints and Private Endpoints both provide secure access to Azure PaaS services, but they work differently: Service Endpoint — routes traffic over the Azure backbone but still uses the service's public IP address; the service endpoint exists at the subnet level. Private Endpoint — assigns a private IP from your VNet to the service; the public endpoint can be disabled entirely, making the service truly private. Private Endpoints provide stronger isolation and can also be accessed from on-premises over VPN/ExpressRoute. For the highest security, Private Endpoints are preferred; Service Endpoints are a simpler, lower-cost alternative.
Restricting Storage with Service Endpoints
After enabling a Service Endpoint on a subnet, you configure the Azure service to only accept connections from that subnet. For a storage account, this means adding a VNet rule in the storage account's firewall settings. After this change, only VMs in the specified subnet can reach the storage account — all other internet traffic is denied. This is a quick, zero-cost way to significantly improve storage account security compared to leaving it open to all internet traffic, especially for accounts hosting sensitive application data.
# Restrict storage account to a subnet with service endpoint
az storage account network-rule add \
--resource-group myRG \
--account-name mystorageacct \
--vnet-name myVNet \
--subnet app-tierVNet Integration for App Services
VNet Integration (distinct from VNet Peering) allows Azure App Service applications to make outbound calls to resources inside a VNet. Without VNet Integration, an App Service's outbound traffic always exits over the public internet — even when calling resources like Azure SQL or Azure Cache for Redis in the same VNet. With VNet Integration enabled, the app's outbound traffic is routed into the VNet and can reach private resources. This requires a dedicated delegated subnet in the VNet with at least a /28 address space.
Transitive Peering with NVA
Because VNet Peering is non-transitive, connecting more than two VNets requires either direct peering between every pair (O(n²) complexity) or a central routing hub. In a hub-and-spoke model, the hub VNet contains a Network Virtual Appliance (NVA) or Azure Firewall that acts as a transit router between spoke VNets. Each spoke adds a UDR pointing all traffic (0.0.0.0/0 or to specific spoke CIDRs) to the NVA's IP in the hub. The NVA then forwards traffic to the correct destination spoke, effectively providing transitive connectivity through the hub.
Peering Limitations to Know
Key VNet Peering limitations: Non-overlapping address spaces required — plan CIDR ranges carefully before creating VNets. Non-transitive — peering A-B and B-C does not connect A-C. Cannot resize a VNet's address space if it has active peerings without temporarily deleting them. Gateway transit — spoke VNets can use the VPN or ExpressRoute gateway in the hub VNet by enabling 'Use Remote Gateways' in the peering configuration, but this requires the hub gateway to be created first. Understanding these limitations is important for designing scalable, maintainable multi-VNet architectures.
Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: VNet Peering connects two VNets over Microsoft's backbone for private, low-latency communication without a VPN, but peering is non-transitive, service endpoints route subnet traffic to Azure PaaS services over the backbone without exposing it to the public internet, and private endpoints are the stronger alternative that assign a private IP to a PaaS service, allowing the public endpoint to be disabled entirely. Next up we explore Azure DNS and Load Balancer essentials.
Frequently asked questions
Is the “VNet Peering and Service Endpoints” lesson free?
Yes — the full text of “VNet Peering and Service Endpoints” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “VNet Peering and Service Endpoints”?
Connect two VNets using VNet peering for low-latency private communication, and use service endpoints to route traffic to Azure services without the public internet. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “VNet Peering and Service Endpoints” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Virtual Networks and Subnets
- Network Security Groups and Application Security Groups
- VNet Peering and Service Endpoints
- Azure DNS and Load Balancer Essentials