Introduction
Virtual network peering allows you to interconnect virtual networks in Azure. By default, resources in one virtual network cannot communicate with resources in another virtual network as if they were on the same network. However, with virtual network peering, you can enable these resources, such as virtual machines, to communicate seamlessly across the Microsoft Backbone Infrastructure. In this article, we will be exploring how to configure virtual network peering, so grab your PC, and let's get our hands dirty!
Prerequisites
To follow this guide, it is advisable to have the following prerequisites
An Azure subscription: If you do not have one, Azure has a free trial subscription and a free subscription for students.
Basic networking knowledge
Once you have these, let’s go ahead and explore our scenario setup to see what we are trying to configure.
Scenario Setup
The following diagram shows the scenario setup. There are two VNets to be peered: vnet-cloudville-1 and vnet-cloudville-2. In these VNets, we have one virtual machine each: vm1 and vm2 respectively. Take your time to understand this diagram, and once you are done, let's get to the real deal!
Method 1: Configuring VNet Peering via Azure Portal
Alright, let's configure our VNet peering using the Azure Portal. We'll walk through this step-by-step.
Creating the VNets
Go to the Azure portal
Click on the Create a resource icon on the portal UI
Search for virtual networks in the marketplace, and click on create
Fill in the region of the VNet, the name, and click on next. Here we are using the East US region
Enter the address space of the subnet you want to add to the VNet
Click on Review + create
After this is complete, repeat the same steps above to create a VNet in the same region named vnet-cloudville-2 and the default subnet having an address space of 20.0.0.0/16. This is to ensure the ip addresses in vnet-cloudville-1 do not overlap with that of vnet-cloudville-2 as this is a requirement for VNet peering
Configuring the VNet Peering
Now, let us configure the VNet peering.
Go to vnet-cloudville-1
On the left pane, click on Peerings
Click on Add to create a VNet peering
Now for the remote virtual network peering, where the remote virtual network is vnet-cloudville-2 and the local virtual network is vnet-cloudville-1.
Scroll down to fill the details of the local vnet peering, then click add
The VNet gets created and be sure to wait till the status shows connected.
This completes the VNet peering configuration. Let’s look at another way of creating VNet peering which is by using ARM templates.
Method 2: Implementing VNet Peering with ARM Templates
We have seen how we can use the Azure portal UI to create a VNet peering, now let us try to create this peering using ARM templates.
Go to the Azure portal
Search for custom templates in the search bar at the top
Then search for a quick start template for creating VNet peerings
Fill in the configuration details for the peering: the resource group, region, local VNet name, and remote VNet name.
Click on Create
To achieve this, repeat the steps above with vnet-cloudville-2 being the local VNet and vnet-cloudville-1 being the remote. Once this is done, you should have a connected status for the VNet peering.
How To Test Our Connection
To validate our VNet peering configuration, you will need to have two virtual machines deployed:
VM1 in VNet-cloudville-1
VM2 in VNet-cloudville-2
Once both VMs are set up, follow these steps to test connectivity:
Retrieve the private IP addresses for both VM1 and VM2.
Connect to VM1 using your preferred method (Azure Bastion, SSH, or Remote Desktop).
From VM1's command prompt or terminal, ping the private IP address of vm2.
A successful ping confirms that the VNet peering is correctly configured. If the ping is successful, the connection uses the Microsoft Backbone Infrastructure exactly as we intended.
Wrapping Up: What We've Learned
In this guide, we have explored the power of Azure VNet peering, interconnecting virtual networks. We walked through two methods of configuration - using the Azure Portal and ARM templates - demonstrating the flexibility of networking in Azure. It is important to note that our example focused specifically on regional VNet peering, where both virtual networks were located in the same Azure region.
Subscribe to our newsletter to get more interesting articles like this!