Theory Of Azure Virtual Network With Four Hands-On Labs


  • Introduction
  • Key terminology used in virtual network
  • Lab 1: Create virtual network using Azure Portal
  • Lab 2: Create virtual network using Azure CLI
  • Lab 3: Create virtual network using PowerShell
  • Lab 4: Create virtual network using ARM template


In this article we will go through the concept of Azure virtual network, what Azure virtual network is and terms in virtual network which are used to create virtual network.

Key terminology used in virtual network

  1. Virtual Network
  2. IP Address
  3. Subnet
  4. Network Interface Card
  5. Load Balancer
  6. Application Gateway
  7. Traffic Manager
  8. Network Security Group
  9. Force Tunnelling
  10. Regional Virtual Network
  11. Cross Premises Network
Virtual Network
Virtual network (VNet) is your own private network in the azure cloud. This provides you a secure way to communicate between your virtual machines and other services which are inside of your virtual network in azure cloud or on-premises.
IP Address
IP addresses are the range of address that define the network and each VM which is part of a virtual network can communicate through this IP address. Each VM with in the Vnet can have private or public IP address, private IP address allows communication between one or more of the  VMs inside the Vnet, but from outside of the Vnet public IP address is used over the internet for communication.
It is a network inside your network. In other words Subnet is small portion of IP address range which is allocated to a virtual network.
Network Interface Card
Network interface card is used to connect the VM through network.
Load Balancer
Load balancer is used to distribute the incoming traffic evenly across a group of servers. This distribution of traffic based on the health probe of servers which are behind the load balancer.
Application Gateway
It is a web traffic load balancer that helps you to manage your traffic to your web application. It is on top of load balancing your workloads, so it can make routing decisions to pass your URL request to the appropriate node. For example if there are two types of requests that come to the application gateway,  one is for images and second one is for videos, than the application gateway can make a decision where to redirect these requests  if we have two dedicated servers, one for serving images and  one  for serving videos.
Traffic Manager
It is also used to distribute the traffic at the DNS level, for example if I have a website and I have traffic from many countries and to manage and I want to distribute the traffic to manage the load in a way that US traffic should go  through the US server and India traffic should go  though the India server.
Network Security Group
It's a  set of rules that work as a filter for your traffic that connects with azure virtual network (Vnet). It allows or denies inbound network security network traffic.
For example if we have a Vnet “xyz” and there are two VMs “A” and “B” inside the Vnet “xyz” and we don’t want RDP connection to access these VMs though the public IP but both the machines can access their RDP using their private IP, then we can define this type of security under the Network Security Group.
Force Tunnelling
Force tunnelling controls the flow of your traffic, it is for inspection and auditing of all internet-bound traffic. It forces all your internet-bound traffic to your on-premise location via sit-to-site VPN tunnelling so you can have the ability to inspect and audit the traffic.
Regional Network
Microsoft Azure has multiple regions. We may have multiple Vnets that may work  in different regions, so the connections between these Vnets which are in different regions comes under this section.
Cross Premises Network
It is a network that is connected to your on-premise network. It allows your azure virtual machine to be  part of your on-premise network.

Lab 1 - Create Virtual Network Using Azure Portal

  • Log in to Azure portal
  • In search bar “Virtual Network” and select it
Figure 1.
  • Now click on the “+ Add” to start creating virtual network
Figure 2.
  • Enter the basic details for virtual network
The first tab, “Basic” is for adding basic details for the virtual network
    • Subscription: “Visual Studio Professional”
    • Resource Group: If you have existing resource group then you can select it, I created an new one called “Learn-Vnet”
    • Name: VnetOne
    • Region: You can select any region; in this lab I am going to select “(US) Central US”
    • Either Click “Review + Create” or you can click “Next : IP Addresses”
Figure 3.
  • Ipv4 address space
    By default, an address space is automatically created. You can click the address space to adjust it to reflect your own values. You can also add additional address spaces
Figure 4.
  • Subnet
    If you use the default address space, a default subnet is created automatically. If you change the address space, you need to add a subnet. Select + Add subnet to open the Add subnet window. Configure the following settings and then select Add to add the values,

    • Subnet name - In this example, we named the subnet “SubNet1”.
    • Subnet address range - The address range for this subnet.
Figure 5.
  • On the Security tab, at this time, leave the default values,

    • BastionHost: Disable
    • Ddos protection standard: Basic
    • Firewall: Disabled
Figure 6.
  • Leave the tag details empty
Figure 7.
  • Select Review + create to validate the virtual network settings.
  • After the settings have been validated, select Create when you hit the create button your virtual network will be created.
But if want to save this information as template for future use the you can click the “Download as template for automation” as shown highlighted in Figure 8.
Figure 8.
  • Click the “Download” to download this as json template as shown in figure 9
  • Or you can add it to your library
Figure 9.
  1. {    
  2.     “$schema”: “”,    
  3.     “contentVersion”: “”,    
  4.     “parameters”: {    
  5.         “location”: {    
  6.             “type”: “string”    
  7.         },    
  8.         “virtualNetworkName”: {    
  9.             “type”: “string”    
  10.         },    
  11.         “resourceGroup”: {    
  12.             “type”: “string”    
  13.         },    
  14.         “addressSpaces”: {    
  15.             “type”: “array”    
  16.         },    
  17.         “ipv6Enabled”: {    
  18.             “type”: “bool”    
  19.         },    
  20.         “subnetCount”: {    
  21.             “type”: “int”    
  22.         },    
  23.         “subnet0_name”: {    
  24.             “type”: “string”    
  25.         },    
  26.         “subnet0_addressRange”: {    
  27.             “type”: “string”    
  28.         },    
  29.         “ddosProtectionPlanEnabled”: {    
  30.             “type”: “bool”    
  31.         },    
  32.         “firewallEnabled”: {    
  33.             “type”: “bool”    
  34.         },    
  35.         “bastionEnabled”: {    
  36.             “type”: “bool”    
  37.         }    
  38.     },    
  39.     “variables”: {},    
  40.     “resources”: [    
  41.         {    
  42.             “name”: “[parameters(‘virtualNetworkName’)]”,    
  43.             “type”: “Microsoft.Network/VirtualNetworks”,    
  44.             “apiVersion”: “2019-09-01”,    
  45.             “location”: “[parameters(‘location’)]”,    
  46.             “dependsOn”: [],    
  47.             “tags”: {},    
  48.             “properties”: {    
  49.                 “addressSpace”: {    
  50.                     “addressPrefixes”: [    
  51.                         “”    
  52.                     ]    
  53.                 },    
  54.                 “subnets”: [    
  55.                     {    
  56.                         “name”: “SubNet1”,    
  57.                         “properties”: {    
  58.                             “addressPrefix”: “”    
  59.                         }    
  60.                     }    
  61.                 ],    
  62.                 “enableDdosProtection”: “[parameters(‘ddosProtectionPlanEnabled’)]”    
  63.             }    
  64.         }    
  65.     ]    
  66. }    
Listing 1.
  •  Clicking “Deploy” button will redirect you to the custom deployment page where you can Edit your template again for changes.
Figure 10.
  • You can change the setting for your virtual network configuration
Figure 11.
  • But I am going to leave this as it is and go back to our “Create Virtual Network” from the breadcrumb screen to complete the creation of our virtual network.
  • Click “Create”
Figure 12.
  • Your virtual network will be ready for use after few moments as shown in figure 13.
Figure 13.

Lab 2 - Create virtual network using Azure CLI

  • Login to Azure portal
  • Click the cloud shell button in the header
Figure 14.
Figure 15.
  • Create a resource group

    az group create –name rgVnet –location eastus  
Figure 16.
  • To verify now go to the Azure portal in the search bar and type “Resource Groups”
Figure 17.
Figure 18.
  • Create Virtual Network with default subnet

    az network vnet create  --name Vnet1 –resource-group rgVnet –subnet-name default  
Figure 19.
If you want to specify your own subnet when creating virtual network
First create a Virtual network without default subnet
  1. az network vnet create –name Vnet2 –resource-group rgVnet  
Listing 2.
Figure 20.
Now create a subnet and ssociate it with virtual network Vnet2
  1. az network vnet subnet create –resource-group rgVnet –vnet-name Vnet2 –name subnet2 –address-prefix   
Listing 3.
Figure 21.
To verify  to the azure portal search for Virtual Network and you will find a virtual network “Vnet2” with Subnet “Subnet2”
Figure 22.

Lab 3 - Create virtual network using PowerShell

Create a resource group
  1. New-AzResourceGroup -Name rgVnet3 -Location CentralUS  
Listing 4.
Figure 23.
Create Virtual Network
  1. $virtualNetwork = New-AzVirtualNetwork -ResourceGroupName rgVnet3 -Location CentralUS -Name Vnet3 -AddressPrefix   
Listing 5.
Go to the virtual network section on the Azure portal and you will see “Vnet3” virtual network has been created but there is no subnet associated with this virtual network as shown in figure 24.
Figure 24.
Create a subnet
  1. $subnetConfig = Add-AzVirtualNetworkSubnetConfig -Name subnet3 -AddressPrefix -VirtualNetwork $virtualNetwork  
Listing 6.
Associate the Subnet with virtual network
  1. $virtualNetwork | Set-AzVirtualNetwork     
Listing 7.
Figure 25.
Figure 26.

Lab 4 - Create virtual network using ARM template

An ARM template is a JSON file with some parameters and with their values, it defines infrastructure and configuration of your azure resources.
  1. {    
  2.     "$schema""",    
  3.     "contentVersion""",    
  4.     "parameters": {    
  5.         "virtualNetworks_Vnet4_name": {    
  6.             "defaultValue""Vnet4",    
  7.             "type""String"    
  8.         }    
  9.     },    
  10.     "variables": {},    
  11.     "resources": [    
  12.         {    
  13.             "type""Microsoft.Network/virtualNetworks",    
  14.             "apiVersion""2020-05-01",    
  15.             "name""[parameters('virtualNetworks_Vnet4_name')]",    
  16.             "location""centralus",    
  17.             "properties": {    
  18.                 "addressSpace": {    
  19.                     "addressPrefixes": [    
  20.                         ""    
  21.                     ]    
  22.                 },    
  23.                 "dhcpOptions": {    
  24.                     "dnsServers": []    
  25.                 },    
  26.                 "subnets": [    
  27.                     {    
  28.                         "name""subnet4",    
  29.                         "properties": {    
  30.                             "addressPrefix""",    
  31.                             "serviceEndpoints": [],    
  32.                             "delegations": [],    
  33.                             "privateEndpointNetworkPolicies""Enabled",    
  34.                             "privateLinkServiceNetworkPolicies""Enabled"    
  35.                         }    
  36.                     }    
  37.                 ],    
  38.                 "virtualNetworkPeerings": [],    
  39.                 "enableDdosProtection"false,    
  40.                 "enableVmProtection"false    
  41.             }    
  42.         },    
  43.         {    
  44.             "type""Microsoft.Network/virtualNetworks/subnets",    
  45.             "apiVersion""2020-05-01",    
  46.             "name""[concat(parameters('virtualNetworks_Vnet4_name'), '/subnet4')]",    
  47.             "dependsOn": [    
  48.                 "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworks_Vnet4_name'))]"    
  49.             ],    
  50.             "properties": {    
  51.                 "addressPrefix""",    
  52.                 "serviceEndpoints": [],    
  53.                 "delegations": [],    
  54.                 "privateEndpointNetworkPolicies""Enabled",    
  55.                 "privateLinkServiceNetworkPolicies""Enabled"    
  56.             }    
  57.         }    
  58.     ]    
  59. }    
  • Microsoft.Network/virtualNetworks: create an Azure virtual network.
  • Microsoft.Network/virtualNetworks/subnets - create a subnet.
Search the "Deploy a custom template" and click it 
Figure 27.
Click the Build your own template in the editor 
Figure 28.
Copy the ARM template (json) file here with parameters and parameter values 
Click save button 
Figure 29.
Select resource group or create
Click "Create + Review"
Figure 30.
ARM template will validate, if it finds any error go back and fix it else we will see "Validation Pass" as shown in figure 31. 
Figure 31.
After a few moments deployment will be complete. 
Figure 32.
Now to verify the "Vnet4", go to the Virtual Network section and you will find Vnet4
Figure 33.


After creating the virtual network, we can add virtual machine inside this virtual network so these machines can start communicating.
After completing these labs don’t forgot to clean your resource if you are not going to use it any more.