On my previous post, i covered the basics of Azure networking. One of the connection types i covered in that post was VNet peering. This post is a tutorial showing you how you can create your own Virtual networks and peer them together.
Portal Method
Step 1: Create the VNets
The first part of the tutorial is to create the Virtual Networks that eventually will be peered together.
Open Azure Portal > Virtual Networks > Add > Create two VNets using the details below:
VNet Name: MyVNet1 Address Space: 10.0.0.0/16 Resource Group: VNetRG1 Location: UK South Subnet: Subnet1-VNet1 Subnet Address: 10.0.0.0/24 VNet Name: MyVNet2 Address Space: 10.1.0.0/16 Resource Group: VNetRG1 Location: UK South Subnet: Subnet1-VNet2 Subnet Address: 10.1.0.0/24
When completed, your Virtual Networks should look as below:
Step 2: Create the Peering
Open Virtual Networks > Select ‘MyVNet1’ > Peerings > Add > Use details below:
Name: MyVNet1-MyVNet2-Peering Deployment Model: Resource Manager Virtual Network: MyVNet2 Allow Virtual Network Access: Enabled
Do the same steps again but this time set the settings below for MyVNet2:
Name: VNet2-VNet1-Peering Deployment Model: Resource Manager Virtual Network: MyVNet1 Allow Virtual Network Access: Enabled
Once completed, a peering should look as below with the status showing as “Connected”:
PowerShell Method
Step 1: Create the Resource Group
New-AzureRmResourceGroup -Name VNetRG1 -Location 'UK South'
Step 2: Create the VNets + Subnets
$Vnet1sn = New-AzureRmVirtualNetworkSubnetConfig -Name 'Subnet1-VNet1' -AddressPrefix '10.0.0.0/24' $vnet2sn = New-AzureRmVirtualNetworkSubnetConfig -Name 'Subnet1-VNet2' -AddressPrefix '10.1.0.0/24' New-AzureRmVirtualNetwork -ResourceGroupName VNetRG1 -Name 'MyVNet1' -AddressPrefix '10.0.0.0/16' -Location 'UK South' -Subnet $Vnet1sn New-AzureRmVirtualNetwork -ResourceGroupName VNetRG1 -Name 'MyVNet2' -AddressPrefix '10.1.0.0/16' -Location 'UK South' -Subnet $Vnet2sn
Step 3: Create the Peering 1 (VNet 1 – VNet 2)
$vNet1=Get-AzureRmVirtualNetwork -Name MyVNet1 -ResourceGroupName VNetRG1 Add-AzureRmVirtualNetworkPeering ` -Name 'MyVNet1-MyVNet2-Peering' ` -VirtualNetwork $vNet1 ` -RemoteVirtualNetworkId "/subscriptions/ENTER YOUR SUBSCRIPTION ID/resourceGroups/VNetRG1/providers/Microsoft.Network/virtualNetworks/MyVNet2"
Step 4: Create the Peering 2 (VNet 2 – VNet 1)
$vNet2=Get-AzureRmVirtualNetwork -Name MyVNet2 -ResourceGroupName VNetRG1 Add-AzureRmVirtualNetworkPeering ` -Name 'MyVNet1-MyVNet2-Peering' ` -VirtualNetwork $vNet2 ` -RemoteVirtualNetworkId "/subscriptions/ENTER YOUR SUBSCRIPTION ID/resourceGroups/VNetRG1/providers/Microsoft.Network/virtualNetworks/MyVNet1"
Step 5: Check connections
Get-AzureRmVirtualNetworkPeering -ResourceGroupName VNetRG1 -VirtualNetworkName myVnet1 | Format-Table VirtualNetworkName, PeeringState Get-AzureRmVirtualNetworkPeering -ResourceGroupName VNetRG1 -VirtualNetworkName myVnet2 | Format-Table VirtualNetworkName, PeeringState
Finish
To clear up the resources delete the “VNetRG1“ Resource group and all of its contents.