Connect Azure VNets using VNet Peering

Hello everyone and happy new year. In the first post of the year, I want to show you how to interconnect Azure Virtual Networks using VNet Peering. Once peered, the VNets appear as one network and all VMs in the peered VNets can communicate with each other directly.

Azure currently supports two types of peering:

  • Virtual network peering: Connecting VNets located in the same region.
  • Global virtual network peering: Connecting VNets across Azure regions.

Prerequisites

  • This tutorial assumes that you already have a Microsoft Azure account configured.
  • You already have two VNets located in the same region and whose IP addresses do not overlap. If you want to know how to create a virtual network in Azure, see this link.

Important: There is no service outage during network peering or after the peering is created.

Azure PowerShell Workaround

If you want to know how to install the PowerShell Azure module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Once you set your default subscription, you’re ready to start.

Set the variables

Here, we define the characteristics of our environment and the resource’s properties. We will use the Get-AzVirtualNetwork cmdlet to assign information about VNet-01 and VNet-02 in two variables.

Create VNet peering

For the peering work correctly, we must create a peering link from VNET-01-NE to VNET-02_NE and vice versa. To create a new VNet peering using PowerShell, you should use the Add-AzVirtualNetworkPeering cmdlet as shown below:

Azure VNet Peering

Important: Once created, the address spaces in any of the peered virtual networks cannot be changed or deleted.

Check the Peering status

If you want to verify the peering status of the VNets, you should use the Get-AzVirtualNetworkPeering cmdlet as shown below:

Get-AzVirtualNetworkPeering

Thanks for reading my post. I hope you find it useful.

If you want to know more about Azure VNet Peering, check out this link:https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-peering-overview