Last updated on April 27, 2023
Organizations rely on efficient and secure communication between various infrastructure components in today’s breakneck speed and interconnected world. Virtual Network Peering is a powerful solution to address these needs by seamlessly connecting resources across different Azure virtual networks. This feature enables organizations to optimize their network performance, reduce latency, and enhance security, all while minimizing costs. In this article, we will delve into the concept of virtual network peering, explore its benefits, and how to peer two virtual networks and test the connection between the two peered virtual networks using Azure virtual machines.
Understanding Azure Virtual Network Peering
Virtual network peering allows organizations to establish a direct connection between two or more virtual networks, enabling resources within these networks to communicate as if they were part of the same network. This connection bypasses the public internet, traversing the Microsoft backbone infrastructure and ensuring secure and efficient network communication. Resources in peered virtual networks in the same region can communicate with each other with the same latency as if they were within the same virtual network.
Here are some things to remember:
- You can use network security groups to restrict access to other virtual networks or subnets.
- The virtual networks to be peered must possess different IP address ranges that do not overlap.
- The virtual networks to be peered can belong to the same subscription or different subscriptions.
- Virtual networks can be peered within the same region or across different regions. Peering virtual networks across different regions is also called Global VNet Peering.
- If there are changes in the address spaces of your virtual network, make sure to initiate a sync after. This will not cause any downtime to your production environment.
How to peer two virtual networks
I have created the following resources for this article:
- TDVnet1
- TDVnet2
Our goal is to peer these two virtual networks.
1. Head over to the Azure portal, search, and click “Virtual Network“. This should take you to the Virtual Network pane.
2. Click TDVnet1 and look for the “Peerings” pane and click “Add” This will redirect you to an Add Peering pane
3. Leave the tick boxes to their default settings. We need to specify two peering link names in this Add Peering pane. The first is for TDVnet1, and the second is for TDVnet2. For this demo, we will name these two: TDVnet1-TDVnet2-Peering and TDVnet2-TDVnet1-Peering. Click Add once you are done naming the two peering names.
4. In the peerings pane, ensure the peering status is Connected.
- Initiated: When you create the first peering, its status is Initiated.
- Connected: When you create the second peering, the peering status becomes Connected for both peerings. The peering isn’t successfully established until the peering status for both virtual network peerings is Connected.
Testing the peering connection
We need to ping two virtual machines using their private IP address to test our connection. I created two virtual machines located in two Azure virtual networks.
- TDVM1 is provisioned in TDVnet1.
- TDVM2 is provisioned in TDVnet2.
1. The image below is before we peer the two virtual networks.
2. After creating the peer, connect to TDMV1 again and initiate the ping command.