Microsoft Learn

Azure Virtual Network Peering

Published: November 15, 2023

Azure Virtual Network (VNet) peering connects two or more Azure virtual networks. VNet peering allows resources in each virtual network to communicate with each other. The virtual networks can be in the same Azure region or different Azure regions. This provides a low-latency, high-bandwidth connection between the virtual networks.

Why use VNet Peering?

VNet peering is essential for building scalable and distributed applications on Azure. It enables:

  • Seamless communication between application tiers hosted in different VNets.
  • Secure connectivity without requiring gateways or encryption for traffic within Azure.
  • Sharing of services and resources across VNets.
  • Hybrid cloud scenarios by connecting on-premises networks to Azure VNets.

Understanding VNet Peering

When you peer two virtual networks, you establish a one-to-one relationship between them. This means that VNet A can be peered with VNet B, and VNet B can be peered with VNet A. This peering connection is non-transitive. If VNet A is peered with VNet B, and VNet B is peered with VNet C, VNet A cannot communicate with VNet C through VNet B.

Diagram illustrating Azure VNet Peering

Conceptual diagram of Azure Virtual Network Peering.

Key Features and Benefits

Types of VNet Peering

  1. VNet to VNet Peering: Connects two VNets within the same Azure subscription or across different subscriptions.
  2. Global VNet Peering: Connects two VNets in different Azure regions. This is crucial for disaster recovery and geographically distributed applications.

Prerequisites for VNet Peering

Configuration Steps (Azure Portal)

To establish VNet peering using the Azure portal, follow these general steps:

  1. Navigate to the virtual network you want to peer.
  2. In the network's settings, select "Peerings".
  3. Click "+ Add" to create a new peering connection.
  4. Configure the peering details, including:
    • Name of the peering connection.
    • The virtual network to peer with (selecting from your subscriptions).
    • Specify address space settings (e.g., Allow virtual network access, Allow gateway transit, Allow forwarded traffic).
  5. Repeat the process on the other virtual network to establish the reciprocal peering.

Example PowerShell Configuration

Here's a snippet demonstrating how to create a VNet peering using Azure PowerShell:

# Variables for VNet A $resourceGroupNameA = "MyResourceGroupA" $vnetNameA = "VNetA" $peeringNameAtoB = "VNetA-to-VNetB" # Variables for VNet B $resourceGroupNameB = "MyResourceGroupB" $vnetNameB = "VNetB" $peeringNameBtoA = "VNetB-to-VNetA" # Get VNets $vnetA = Get-AzVirtualNetwork -ResourceGroupName $resourceGroupNameA -Name $vnetNameA $vnetB = Get-AzVirtualNetwork -ResourceGroupName $resourceGroupNameB -Name $vnetNameB # Create peering from VNet A to VNet B Add-AzVirtualNetworkPeering -Name $peeringNameAtoB ` -VirtualNetwork $vnetA ` -RemoteVirtualNetworkId $vnetB.Id ` -AllowVirtualNetworkAccess # Create peering from VNet B to VNet A Add-AzVirtualNetworkPeering -Name $peeringNameBtoA ` -VirtualNetwork $vnetB ` -RemoteVirtualNetworkId $vnetA.Id ` -AllowVirtualNetworkAccess Write-Host "VNet peering created successfully between $vnetNameA and $vnetNameB."

Important Considerations

When using VNet peering, especially with gateway transit enabled, ensure that your routing configurations are correct to avoid network loops or connectivity issues. Also, be mindful of the peering limits imposed by Azure.

Troubleshooting VNet Peering

Common issues include:

Use Azure Network Watcher's connection troubleshoot features to diagnose connectivity problems.

Conclusion

Azure Virtual Network peering is a powerful and flexible service that simplifies and enhances connectivity between your virtual networks. By understanding its features and proper configuration, you can build robust, scalable, and secure cloud architectures.

For advanced scenarios and detailed configuration options, refer to the official Azure documentation and best practices.