DEV Community

Cover image for How to communicate with two VMs in the same VNet
Shish Singh
Shish Singh

Posted on • Updated on

How to communicate with two VMs in the same VNet

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

  • 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

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

e.g.; VM2

Image description

  • 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

*** 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

SuccessFromVm2

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
Subscribe to my channel:
Youtube Channel
Instagram:
Destination Hideout

Top comments (4)

Collapse
 
neha_srivastava_b7ce8245a profile image
Neha Srivastava

Great vlog explaining the concept of virtual networks in Azure and how to connect two virtual machines present in the same virtual network. The step by step guide provided on creating a resource group and two virtual machines is easy to follow and understand. Looking forward to more such informative vlogs on Azure!

Collapse
 
shishsingh profile image
Shish Singh

Thank you..!

Collapse
 
sumansaha15 profile image
Suman Saha

Very eloquently written with all necessary dots connected. I have one question on the security side. As you opened port 3389 for RDP and also disabled both public and private defenders, won't it increase the attack surface on this system? If this is for a PoC only for just to prove the idea then it may be okay. But for an enterprise scale, we may need to consider a Bastion Host to jump into the VMs and also secure the VNets/ SubNets with NSGs.

Keep up the good work Shish!!

Collapse
 
shishsingh profile image
Shish Singh

Thank you for your response. Yes, this is a POC. Alternatively there are many ways where we should/may have firewall to safe guard our network and VMs.