DEV Community

Cover image for Creating a Virtual Network with Two Virtual Machines that can ping each other.
Tunde Oretade
Tunde Oretade

Posted on

Creating a Virtual Network with Two Virtual Machines that can ping each other.

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
  • select virtual networks from the sidebar. virtual networks
  • Click +create at the top of the create network page. +Create
  • 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 Create new
  • Under the instance details label, provide a name for the network and select a suitable Region.
    Instance details

  • Click the IP Addresses tab at the top of the page, to add a subnet.
    IP Addresses

  • 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

  • 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

  • Leave the Subnet Purpose at Default.
    Subnet purpose

  • Change Subnet name to vnet1-subnet.
    Change subnet name

  • 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

  • Click Review + create to run validation.
    Review + create

  • When you see the notification that Validation passed, click the
    Create button to deploy the Virtual Network.
    create
    deployment in progress
    deployment is complete

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
  • Click the hamburger menu button (top left of the page) and select virtual machines. menu button select virtual machines
  • Click + Create icon and then select Virtual machine. create virtual machine
  • 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
  • At the Instance details heading and the Virtual machine name click the input box and name the virtual machine as vm1. virtual machine name
  • At the Region label select a suitable region. In this case, I selected East US. Region
  • Set Availability options to No infrastructure redundancy required Availability options
  • Set Security type to Standard. Security type
  • At the Image label, select windows server 2019 Datacenter - Gen 2. Image
  • set vm architecture to x64. VM Architecture
  • Next, untick Run with Azure spot discount Run with Azure spot discount
  • 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
  • Do not Enable Hibernation. In my case Hibernation isn't supported for my VM size. Enable Hibernation
  • 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
  • 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
  • Do not tick the Licensing section as well. Licensing
  • 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
  • When you see the notification that Validation passed, click the Create button to deploy the first Virtual Machine. deploy virtual machine deploying deployment in progress deployment complete
  • 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
  • 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 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
  • Select Download RDP file. Download RDP file
  • Open the downloaded RDP file for vm1. Open the downloaded RDP file
  • 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

  • You may receive a certificate warning prompt. Click continue to create the connection to your deployed virtual machine.
    certificate warning prompt

  • 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

  • Type firewall.

  • Select windows defender firewall in the search results.
    windows defender firewall

  • Click turn Windows Defender Firewall on or off
    turn Windows Defender Firewall on or off

  • 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
    Modify the firewall setting II

  • 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

  • Select PowerShell from the search result listing.

  • After PowerShell completes launching, type ping vm2 into the interface.
    Ping vm2

  • 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

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

Photo by Shubham Dhage on Unsplash

Top comments (0)