In this post we can learn how to create 2 VNET & enable VNET Peering between both.
Azure VNET
Azure VNET allows private network within Azure. VNET should specify an Address Space. VNET creates Subnets which are Segments within the Address Space.
VNET Peering
It is possible for 2 VNETs to communicate with each other using VNET Peering. VNET Peering bypasses Internet, Public IP Addresses & Communicate with the Local Azure Network which is faster & higher bandwidth without any encryption. Thus the VNET Peering is faster & safer too.
VNET allows Resources (eg: VMs) communicate with each other as if they are in the same network.
VNET can be configured across regions & subscriptions too.
Create VNET
Open Azure CLI command interface & Run the following commands.
az login
az network vnet create –resource-group “jp_azure” –name VNET1 –address-prefix 10.1.0.0/16 –subnet-name Apps –subnet-prefix 10.1.1.0/24 –location eastUS
az network vnet create –resource-group “jp_azure” –name VNET2 –address-prefix 10.1.0.0/16 –subnet-name Apps –subnet-prefix 10.1.1.0/24 –location eastUS
az network vnet list –output table
Create VMs
Now we can create VM in each of the VNETs.
az vm create \ –resource-group “jp_azure” \ –no-wait \ –name VM1 \ –location northeurope \ –vnet-name VNET1 \ –subnet Apps \ –image win2016datacenter \ –admin-username admin \ –admin-password administrator1!
az vm create \ –resource-group “jp_azure” \ –no-wait \ –name VM2 \ –location northeurope \ –vnet-name VNET2 \ –subnet Apps \ –image win2016datacenter \ –admin-username admin \ –admin-password administrator1!
Create VNET Peering
Now we can create VNET Peering using the following commands.
az network vnet peering create \ –name VNET1-TO-VNET2 \ –remote-vnet VNET1 \ –resource-group JP-Resource \ –vnet-name VNET2 \ –allow-vnet-access
Following is for reciprocal connection.
az network vnet peering create \ –name VNET2-TO-VNET1 \ –remote-vnet VNET2 \ –resource-group JP_azure \ –vnet-name VNET1 \ –allow-vnet-access
Testing
Login to the VM1 using Public IP and Ping to the VM2 using Private IP. If the connection succeeded it means the VNET Peering was created successfully.
Summary
In this post we have explored how to create 2 VNET & enable VNET Peering between both.