Azure Virtual Network (VNet) Peering enables the connection of two or more virtual networks in Azure. Connectivity-wise the two peered networks appear as one. Peered traffic is routed through Microsoft’s private network and not over the public internet. An Azure virtual network is a software-defined network with a custom address space and segmented subnets.

There are two types of peering offered by Azure.

Virtual network peering enables connecting virtual networks within the same Azure region. Global virtual network peering connects traffic across Azure regions.

Why would we want to use virtual network peering to connect two different virtual networks? There are a couple of benefits to peered networks.

Utilize a low-latency and high-bandwidth connection between resources in different virtual networks. Transfer data across Azure subscriptions, tenants, and regions. No downtime when configuring peered virtual networks.

In this article, we are going to demonstrate creating a peered network using Azure Powershell commands. You will need the Azure PowerShell module to perform these commands.

Connecting Virtual Machines via Peered Virtual Networks

In this tutorial, we are going to create two new resources groups, virtual networks, and virtual machines. Once everything has been set up, we will peer the virtual networks between the two Azure VM’s and demonstrate that they can indeed communicate. First, we need to import the Az module and authenticate to Azure using the Connect-AzAccount cmdlet.

Next, for the sake of this tutorial, we are going to create two resource groups where our virtual machines and virtual networks will reside.

Before we provision our virtual machines, we first need to create the different virtual networks that we would like to peer together.

We can verify that the virtual networks have been created successfully, using the Get-AzVirtualNetwork cmdlet.

To demonstrate that we can connect two virtual networks, we need resources from within those networks to send traffic from. To do this, we will create two standard virtual machines each located in different virtual networks.

Finally, we will connect the two virtual networks by using Add-AzVirtualNetworkPeering. After retrieving the virtual network configurations, we will pass that information to create our peered connection.

Using Get-AzVirtualNetworkPeering we can see that our peered networks are now available for use.

Demonstrating the Peered Virtual Network Connection

Now that everything is properly connected, we can show that the virtual machines can ping each other successfully. First, make sure that your network adapters are on a private network and that you have allowed the File and Printer Sharing (Echo Request – ICMPv4-In) firewall rule. Otherwise, even with a peered network, your ping tests will most likely fail.

As you can see below, both sides of the peered virtual network connection work as expected.

Conclusion

Connecting Azure Virtual Networks through peering enables different resources to easily communicate and share data securely. With PowerShell, this task is made easy and can be quickly incorporated into deployment scripts. Even though you may be using separate virtual networks for both policy and security reasons, you are not limited in your VM connectivity. Get started with Azure Virtual Networks today!