Create VNET & VNET Peering in Azure using CLI

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 –subnet-name Apps –subnet-prefix –location eastUS

az network vnet create –resource-group “jp_azure” –name VNET2 –address-prefix –subnet-name Apps –subnet-prefix –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


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.


In this post we have explored how to create 2 VNET & enable VNET Peering between both.

Azure VM–Save Cost by Auto-Shutdown

Azure VM definitely gives lot of flexibility like:

  • High-end Hardware Configuration
  • Ready Software
  • High-speed Internet
  • Quick Availability

At the same time the Cost can be Quite Huge if one is considering High Configuration with Costly Software Licenses.

Save Cost

Most of the time I have noticed the Users will be using VM only less than 6 hour per day.  Rest of the time it will be left alone.  This is simply eating lot of $ per hour if you calculate the hours X days for a Month.

Auto-Shutdown Feature

Here the Auto-Shutdown feature comes handy. Here are the steps to use it:

Open VM > Control Panel


In the appearing blade choose the Enabled option.


You can also set an Email for notifying you before the shutdown.