How to communicate with two VMs in the same VNet
Tags: azurevnets, virtualnetworks, azure
Published: 2023-03-24 21:43:28

Before we move ahead and start connecting two virtual machines present in the same virtual networks. Let's first understand what virtual network is..?

## Virtual Network

A virtual network in azure is a logical separation of the azure cloud dedicated for your subscription. You can treat it as your own personalised network present in the cloud. 

Each virtual network just like any other physical network can further be divided into multiple sub networks. It won't be wrong to simply state a subnet is a range of IP addresses in the virtual network. 

Coming back to our topic if we wish to connect two virtual machines present in the same virtual network we need to move ahead and first create the required resources. 

## Steps to follow

*** Create the resource group(RG)

First we will have a create a resource group. This resource group will hold all our resources and will help us in logically handling all the resources at one place and in one go.
e.g.; VM_CON_RG

*** Create two virtual machines 

- select the resource group created in point 1 (You may also create a resource group while creating the first virtual machine).

- You may select a higher end machine but for understanding the topic let's consider windows server 2019 image as an example. 

e.g.; VM1

![Virtual Machine 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0npv1ygvy7gac2x0t8vt.JPG)

- Public inbound ports are allowed and inbound ports is RDP(3389).

- Keeping all the settings as default for VM1. The final step is to review and create the VM. Meanwhile, remember the virtual network(vnet) of the first machine.
While creating the second virtual machine we will have to use the same virtual network. Also, Copy the public ip address of the virtual machine. 

If not created please create one. e.g.;10.0.0.0/24

![VM1_VNet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nsmvo3owgnztelqk0jk.JPG)

- Now move ahead and create the second virtual machine keeping all the settings and configuration as it is. 

e.g.; VM2

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbya7epm8eqdrahy1oe0.JPG)

- Make sure you check the virtual network while creating the second virtual machine. Select the same VNet as of virtual machine 1. Copy the public ip address of the virtual machine.

If not created please create one. e.g.;10.1.0.0/16

- Once all the configurations and settings are verified please move ahead and create the virtual machine. 

*** Once done connect to the virtual machine 1 using RDP. Open the windows setting dashboard. Here, select Network & Settings. Click on windows firewall sub option in the change your network settings sub-section.  

![Windows_Defender](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ic1t34ayqjz2jp2cf5x.JPG)

*** Disable both public and private windows defenders. 

*** Also, If created try and connect to the virtual machine 2 using RDP. 

*** Please repeat step 3 & 4 for virtual machine 2.

*** Now open the Windows PowerShell in virtual machine 1 and try to ping virtual machine 2 with its ip address. 


![PingToVm2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzn4qgjfh08ognpm65l5.png)

![SuccessFromVm2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hq2bzl93k7a5y9vv4k3h.png)

Voila...It's done.


Note: In the next blog we will try and understand VNet Peering with an example. 


## Connects

Check out my other blogs: 
[Travel/Geo Blogs](shishsingh.wordpress.com)
Subscribe to my channel: 
[Youtube Channel](youtube.com/@destinationhideout)
Instagram:
[Destination Hideout](https://www.instagram.com/destinationhideout/)