How to create communication between two virtual machines using virtual network and subnet
Tags: azure, developer, cloudskills, cloudcomputing
Published: 2023-12-16 23:14:35

## Introduction
Creating private networks in Azure requires the use of Azure virtual networks. They provide safe communication between various Azure resources, the internet, and on-premises networks.

## Creating a virtual network and subnet
- Log in to your azure account.
- Click create a resource
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ipp1ekp3fojovmd6xnb.png)
- Search for virtual network in the Market place
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zki4801xus2g7betv479.png)
- Fill in the project details which comprises subscription and resource group
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4k6x0dkzwe0gjffxp4qf.png)
- Then fill the instance details which comprises virtual network name and region.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ci1vslkrha23nfskq19.png)
- Change the tab from Basics to Ip addresses
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncx7oudqaww3cm73gj2y.png)
- Edit the Ipv4 address space to 10.1.0.0
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7mrbkrxu11o3ic3tmql.png)
- Click Default to edit the subnet, give a name for the subnet and change the starting address to 10.1.0.0 and leave the other settings as default and click save
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/diw4h23e86cryl2nck3x.png)
- Click review + create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99uoh05lc4glo5c2cesz.png)
- Click create once validation is passed
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/widaldugnurfsoe6flgt.png)

## How to Create two virtual machines in the same virtual network
- Click create a resource
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09zt4jgubficbnzrxlko.png)
- Search for virtual machine in the market place and click create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63pbsah5pdb0xwlm3pzc.png)
- Fill the project details which comprises of subscription and resource group
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hi11o5y6a63og70f5ne5.png)
- Fill in the instance details
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wz2wi62bz756rnlxt9cz.png)
- Fill the Administrator account
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rdbgn6p3tnqcmogc2b99.png)
- Leave the inbound port rules as default
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9sb7b2avxazk2zon6fv.png)
- Click Networking tab and set the virtual network to the virtual network created earlier, leave other settings as default.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2d0wiswp622se5j0ohfa.png)
- Click review + create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/af6ek264qznyfyf14ecf.png)
- Click create once validation is passed
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/19jrlszqz88cwtq1fb9m.png)
- Use this method to create another virtual machine and still set it to the virtual network created earlier. The two virtual machines are VM1 and VM2.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/822l4tjrnra04tj2b2xd.png)

## How to test if the Virtual machines can communicate using Ping.
- open VM1 by clicking on it and click connect in the overview page
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9te13dhbfcekxwfiq5wh.png)
- Click select under Native RDP
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3j6wf6u9esq0oyx6hds.png)
- This will open a pane to download RDP file
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kvbkenjfpakny84ozp3y.png)
- After downloading the RDP file click on the file to launch it and click connect
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dh5g357e7qgtrlovpr5m.png)
- Enter your username and password and click Ok
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jooln7lw1bz61hkltrx5.png)
- Click yes 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1oc8vl8ij35xb0vxnnp.png)
- This will take you to the desktop page of your virtual machine and repeat this process to launch the second virtual machine 
- We need to disable the public and private firewall of both virtual machine by searching for firewall in the search tab and click on Windows Defender Firewall
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jtmtbo49sluwxh9mwfvs.png)
- Click on Turn Windows Defender Firewall on and off
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/odwjkj14qbbat1452rl4.png)
- Click on Turn Windows Defender Firewall on and off for both public and private settings, click okay.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gs61nsw61htls1yoiim.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49sp7gw5wjlwmjsoq6gn.png)
From the first virtual machine open powershell command prompt by searching powershell in the search tab and click powershell
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8p2q0zyq8kxd1gr47zha.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3m25dz1vs370yjcurr9k.png)
- In the powershell command prompt, run the code: ping vm2
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tj8b4ohsxn3xpywntsma.png)
This shows that the first virtual machine is connected to or can communicate with the second virtual machine