Creating a Virtual Network with Two Virtual Machines that can ping each other.
Tags: azure, virtualnetwork, virtualmachines, subnet
Published: 2024-07-12 21:46:36

---
title: Creating a Virtual Network with Two Virtual Machines that can ping each other.
published: true
description: How to create a virtual network that consists of two virtual machines that can communicate with each other.
tags: Azure, VirtualNetwork, VirtualMachines, Subnet
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zdqhzl861ueljv7k6lt.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2024-07-10 02:37 +0000
---
#INTRODUCTION
Today I will be writing about how to create a Virtual Network with Two Virtual Machines that can ping each other. This process involves setting up a virtual environment where multiple virtual machines (VMs) can communicate seamlessly, mimicking a real-world network setup.
In this article, I will walk through the steps necessary to create a virtual network and configure two virtual machines to ensure they can successfully ping each other, demonstrating effective connectivity and interaction within the virtualized environment.

##STEP 1: CREATE A VIRTUAL NETWORK & A SUBNET
- From the Azure Portal home page, at the top left corner of the page, 
  click the hamburger (menu) button.
![menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tuw5esmgoxryd11f4vyz.png)
- select **virtual networks** from the sidebar.
![virtual networks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/85qnebix30pl2vws1dsd.png)
- Click **+create** at the top of the create network page.
![+Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5aqo45p951f4q5q6gau6.png)
- At the **Basics** tab, under **Project details** and at the **Resource 
  group** label, click **create new** link. Provide a name for the 
  resource group and click **Ok**.
![Basics](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/il1n839ibwjngh0fgrbm.png)
![Create new](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a3e9zaio92rza1pcy45h.png)
- Under the **instance details** label, provide a **name** for the network and select a suitable **Region**.
![Instance details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6ai7qd1y567bah9tydn.png)

- Click the **IP Addresses** tab at the top of the page, to add a subnet.
![IP Addresses](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qi39vrjo1wy3h4kqedmn.png)
- At the dropdown menu displayed above the **address space** box on the 
  displayed page, check that the dropdown is set to **Add IPv4 address 
  space**
![drop-down menu above address space box](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrjpj8dliysbann6b38u.png)
- In the address space box, change **Subnet address range** to 
  **10.1.0.0/16** (This is usually the default IP address so you may not 
  need to change it in this instance). 
- locate the pen icon at the bottom corner, in the address space box (next 
  to the garbage can icon). Click on this icon to edit the default 
  **Subnet** name/add a subnet.
![address space box](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ai4o02hnuoh4ixttpy4h.png)
- Leave the **Subnet Purpose** at **Default**.
![Subnet purpose](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/elln9ojmsnmgjamtchaj.png)
- Change Subnet **name** to **vnet1-subnet**.
![Change subnet name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0jgkebv9oheg858alvv.png)
- Also, change **Subnet address range** to **10.1.0.0/24** using the 
  **size** label. Leave all other settings as their defaults.
- Click **Add** to close the **Add a Subnet** pane. This 
  completes the creation of the subnet. 
![change subnet address range and click add](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sizaykobs8oh6p8ucho7.png)
- Click **Review + create** to run validation.
![Review + create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i56dnr2ouwlfpta855y2.png)
- When you see the notification that Validation passed, click the 
  **Create** button to deploy the Virtual Network.
![create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7khnlfx6sjcsss29zh5.png)
![deployment in progress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gox92vsdpfk0kv4d0n1.png)
![deployment is complete](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcwfe0wlxmhut5qcsi0v.png)

##STEP 2: CREATE TWO VIRTUAL MACHINES IN THE NETWORK (VIRTUAL NETWORK)
- After the virtual network deployment is complete click **Go to resource**.
![Go to resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xp2o4jv1mycye14d2ago.png)
- Click the hamburger menu button (top left of the page) and select **virtual machines**.
![menu button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3pf4d71njnncckqwy9n0.png)
![select virtual machines](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xelx4a1ib0rxnvf7n83.png)
- Click **+ Create** icon and then select **Virtual machine**.
![create virtual machine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5zvode4rzgd6b0vz9oqq.png)
- On the **Basics** tab, at the **Project details** and at the **Resource group** label, select the resource group created earlier from the drop-down list of resource groups. This is the deployment ID.
![select the resource group created earlier from the list of resource groups](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmal872tj7wn36u6ecun.png)
-  At the **Instance details** heading and the **Virtual machine name** click the input box and name the virtual machine as **vm1**.
![virtual machine name](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72ials2uxuy6cakjynl6.png)
- At the **Region** label select a suitable region. In this case, I selected **East US**.
![Region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nrx0b11rqg2g4ur1b1v9.png)
- Set **Availability options** to **No infrastructure redundancy required**
![Availability options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vb76vi7olsxs54p5f69v.png)
- Set **Security type** to **Standard**.
![Security type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4sx89ouwcpiw329m5mor.png)
- At the **Image** label, select **windows server 2019 Datacenter - Gen 2**.
![Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/by24cubwe7gx9qt2sl9o.png)
- set **vm architecture** to **x64**.
![VM Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50ynlut80i05t8ouxrgu.png)
- Next, untick **Run with Azure spot discount**
![Run with Azure spot discount](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aftzori572edjvfcz66g.png)
- Then, set **size** to **Standard_Dc4ads_cc_v5..**. At times the size required may not be listed. If this happens select the **see all sizes** link. This will take you to another page to select a VM size.
![Size](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ou78l9pedrgreghveqge.png)
- Do not **Enable Hibernation**. In my case Hibernation isn't supported for my VM **size**.
![Enable Hibernation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5t6vf4ptr8tmjr2dyugc.png)
- At the **Administrator account** heading, select a **Username** and **Password**. Also **confirm password** by re-typing the password in the input box at the **confirm password** label. (These are the details that will be required to access the Virtual machines when it is in operation.)
![Administrator account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gc4hunm8wzwk6y57bzwd.png)
- At the **Inbound port rules** heading leave the **Public inbound ports** set at the default.
- set **select inbound ports** to default which is RDP(3389).
![Inbound port rules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c3kcp70lf320jq1o62e.png)
- Do not tick the **Licensing section** as well.
![Licensing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mitz1hv6dewjtpdenhva.png)
- Click the **networking** tab at the top of the page. Make sure that **vm1** is placed on the **Vnet1-subnet** virtual network.
- Click **Review + create** to validate the configurations.
![Review + create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb43xo7kv7v5tmio1c63.png)
- When you see the notification that Validation passed, click the 
  **Create** button to deploy the first Virtual Machine. 
![deploy virtual machine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7czkgwu5tmlxfzmytzf.png)
![deploying](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljmp4he22k96k9jeq3k6.png)
![deployment in progress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hv5ecz9d24wjpna66i50.png)
![deployment complete](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcfy48a3sf24dgrxnscz.png)
- Next, create the Second virtual machine in the same virtual network following the steps listed under this heading. Make sure the second Virtual machine has a different name and a different IP address for networking.

##STEP 3: TEST THE CONNECTIONS
- to view the deployed virtual machines, search for virtual machines in the search bar at the top of the page.
- At the listing, click **vm1** to open it. 
![Select vm1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sn4b5lfeewh231m8wv7v.png)
- at **vm1** overview page, you will notice that the status is *Running*. Click the IP address link at the **Public IP address** label to increase the timeout settings. You can check [here](https://dev.to/tundeiness/setting-up-a-windows-11-virtual-machine-with-azure-on-a-macos-88m) to see how it is done. This is one of the industry's best practices. However, I didn’t increase the Timeout for my virtual machine in this article.
- Still at the **vm1** overview page, click **Connect** at the top of the page.
![connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dyhydv8owyf4fq3iv7d.png)
- Select **Download RDP file**.
![Download RDP file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96s3cmi8hjct10pe19p9.png)
- Open the downloaded RDP file for **vm1**.
![Open the downloaded RDP file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnmg65jylpdpuh9bkf5c.png)
- When prompted, click **connect**.
- Provide the credentials created for **administrator account** while creating **vm1** virtual machine. Provide the **password** and click **ok**.
![Provide the credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0sz7vy4568is6ufiz13i.png)

- You may receive a certificate warning prompt. Click **continue** to create the connection to your deployed virtual machine.
 ![certificate warning prompt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4hewm345yan78xms9196.png)

- Follow the same process listed above to also open **vm2**.
- Now that both virtual machines are open, go to **vm1** interface. Click on the **search** button icon at the bottom of the page.
![search button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5y0xiiz33fep7v7ooeew.png)
- Type *firewall*.
- Select *windows defender firewall* in the search results.
![windows defender firewall](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5wzhszhnnmv33i751e9.png)
- Click **turn Windows Defender Firewall on or off**
![turn Windows Defender Firewall on or off](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vr686ljs5zsab2kkcwj6.png)
- Modify the firewall setting by clicking **turn off windows defender firewall** for **Private network settings** and **Public network settings**
- click **Ok**.
![Modify the firewall setting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kz5gho82hrevdjimxjih.png)
![Modify the firewall setting II](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n075z1c2d3o2hsb57cf2.png)
- Disable the firewall for **vm2** just like it was done for **vm1**.
- Next, in **vm1** click **search** icon at the bottom of the page and search for **powershell**
![search for powershell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0toc1jcie6a2nv2aekvt.png)
- Select **PowerShell** from the search result listing.
- After PowerShell completes launching, type **ping vm2** into the interface.
![Ping vm2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9ye303cz1ky2rtohyzu.png)
- If you can see the following display in the image below, that means the connection was successful. I have successfully pinged **vm2** from **vm1**.
![Successful pinging](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/msb4y4xt4t3ac7x1osj5.png)

#CONCLUSION
In this article we have done the following:
- Created a Virtual Network and a Subnet
- Deployed two virtual Machines onto the virtual network
- Configured them to allow one virtual machine to ping the other within 
  that virtual network, and
- Tested the connection of the two virtual machines in the network.

Another article about virtual networks in Azure can be found [here](https://dev.to/tundeiness/how-to-deploy-a-hub-virtual-network-in-azure-14cj)

Photo by <a href="https://unsplash.com/@theshubhamdhage?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Shubham Dhage</a> on <a href="https://unsplash.com/photos/a-black-and-white-photo-of-a-bunch-of-cubes-gC_aoAjQl2Q?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Unsplash</a>