How To Create VNet In Azure

How To Create Vnet In Azure

In this Azure tutorial, we will discuss how to create VNet in Azure. Along with that, we will also discuss a few other topics as below

  • What is vnet in azure
  • How to create a virtual network Azure Portal
  • Create VNet in Azure PowerShell
  • How to create virtual network in Azure using PowerShell
  • Creating VNet using Azure CLI
  • Delete a virtual network in Azure
  • Azure VNet Peering
  • Azure subnet

How To Create VNet In Azure

Before discussing how to create VNet in Azure, we should have a little bit of idea of what is VNet in azure and then we will discuss the Prerequisites needed to create VNet in Azure and then we will discuss the steps to create VNet in Azure.

What is VNet in Azure

Azure Virtual Network (VNet) is your private network in Azure. It represents your Private network on the cloud. Your Azure virtual machines (VMs) can communicate securely with each other using the virtual network created by you.

For higher security, you have the provision to divide a VNet into multiple subnets.

This is a small introduction to the virtual network in azure. Now, Assuming you have a bit idea of what is VNet in Azure, let’s discuss the Prerequisites needed to create VNet in Azure.

Prerequisites

You must have an Azure account or Azure Subscription. If you don’t have it till now, Create an Azure Free Account now.

How to create a virtual network Azure Portal

Well, it’s quite easy to create VNet in Azure using Azure Portal. Follow the below steps

  1. Log in to the Azure Portal (https://portal.azure.com/).
  2. Search for Virtual Network and click on the search result Virtual Networks.
Create VNet In Azure using Azure Portal

Or, for the same steps, you can click on the + Create a resource option from the top left corner in the Azure Portal.

Create Virtual Network In Azure using Azure Portal

Search for Virtual Network and click on the search result Virtual Network.

Create a Virtual Network In Azure using Azure Portal

3. Click on the Create button on the Virtual Network window.

Create a VNet in Azure

4. On the Create virtual network window, select the Basics tab and then provide the below details

  • Subscription: Select the subscription that you want to use here.
  • Resource group: Select an existing resource group or you can create a new resource group using the Create new link.
  • Name: Provide a name for the virtual network.
  • Region: Select the Region.

Click on the Next: IP Addresses > button to navigate to the IP Addresses window.

How to create a VNet in Azure

5. Now, it will validate all the data entered by you and show you the Validation passed. Finally click on the Create button to create the Virtual network.

Create VNet In Azure in Azure Portal

6. Now, it will show you “Your deployment is complete”. Click on the Go to resource button to navigate to the virtual network.

create vnet in azure

Create VNet in Azure PowerShell

Well, Let’s discuss here how to create virtual network in Azure using PowerShell. Before discussing the actual functionality, we should know the prerequisites needed here to create a virtual network in Azure using PowerShell.

Prerequisites

Below are the prerequisites needed to create VNet in Azure using PowerShell.

The first step is we need to create a resource group. The resource group will be responsible to host the virtual network.

Creating a resource group using PowerShell

Execute the below Azure Powershell cmdlet to create a resource group in Azure.

$rsgrp = @{
    Name = 'Demo980'
    Location = 'EastUS'
}
New-AzResourceGroup @rsgrp

Once you will execute the above Azure PowerShell cmdlet, you will get the output like below

ResourceGroupName : Demo980
Location          : eastus
ProvisioningState : Succeeded
Tags              : 
ResourceId        : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72f6gbd1/resourceGroups
                    /Demo980

You can check it out below

Create VNet in Azure using PowerShell

Here, “Demo980” is the name of our resource group and “EastUS” is the name of the location.

Now the time to create the Virtual Network as the next step.

Creating Virtual Network PowerShell

Execute the below Azure PowerShell script. Where TSInfoVNet1 is the name of the virtual network. Demo980 is the resource group name that we have created above

$myvnetw = @{
    Name = 'TSInfoVNet1'
    ResourceGroupName = 'Demo980'
    Location = 'EastUS'
    AddressPrefix = '10.0.0.0/16'    
}
$virtualNetwork = New-AzVirtualNetwork @myvnetw

Once we will run the above script, TSInfoVNet1 virtual network will be created for us.

Now just to cross check, i have logged in to Azure Portal and could see the virtual network got created sucessfully.

Creating Virtual Network PowerShell

Now the next step is to add a subnet.

Adding a subnet

You can use the below Azure PowerShell script to add a subnet.

$subnet = @{
    Name = 'default'
    VirtualNetwork = $virtualNetwork
    AddressPrefix = '10.0.0.0/24'
}
$subnetConfig = Add-AzVirtualNetworkSubnetConfig @subnet

Now we have added a subnet, Not the time to associate the subnet to the virtual network.

Associating the Subnet to the Virtual Network

Use the below Azure PowerShell cmdlet to associate the subnet to the Virtual Network.

$virtualNetwork | Set-AzVirtualNetwork

Once you will execute the above PowerShell cmdlet, you will get the output as below

Name                   : TSInfoVNet1
ResourceGroupName      : Demo980
Location               : eastus
Id                     : /subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceG
                         roups/Demo980/providers/Microsoft.Network/virtualNetworks/TSI
                         nfoVNet1
Etag                   : W/"115d206e-1651-444c-b382-774b94adef37"
ResourceGuid           : fb1b0c6a-646a-441c-a956-a256027d2045
ProvisioningState      : Succeeded
Tags                   : 
AddressSpace           : {
                           "AddressPrefixes": [
                             "10.0.0.0/16"
                           ]
                         }
DhcpOptions            : {
                           "DnsServers": []
                         }
Subnets                : [
                           {
                             "Delegations": [],
                             "Name": "default",
                             "Etag": "W/\"115d206e-1651-444c-b382-774b94adef37\"",
                             "Id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd
                         1/resourceGroups/Demo980/providers/Microsoft.Network/virtualN
                         etworks/TSInfoVNet1/subnets/default",
                             "AddressPrefix": [
                               "10.0.0.0/24"
                             ],
                             "IpConfigurations": [],
                             "ServiceAssociationLinks": [],
                             "ResourceNavigationLinks": [],
                             "ServiceEndpoints": [],
                             "ServiceEndpointPolicies": [],
                             "PrivateEndpoints": [],
                             "ProvisioningState": "Succeeded",
                             "PrivateEndpointNetworkPolicies": "Enabled",
                             "PrivateLinkServiceNetworkPolicies": "Enabled",
                             "IpAllocations": []
                           }
                         ]
VirtualNetworkPeerings : []
EnableDdosProtection   : false
DdosProtectionPlan     : null

Creating VNet In Azure Azure CLI

Well, we have already discussed above, how to create VNet using Azure Portal and How to create VNet using PowerShell. Now, let’s discuss how to create VNet using Azure CLI. But before that we should know the Prerequisites needed here.

Prerequisites

Below are the Prerequisites needed for creating the virtual network using Azure CLI.

  • You must have an Azure account or Azure Subscription. If you don’t have it till now, Create an Azure Free Account now.
  • You need to install the latest version of Azure CLI. If you have not yet installed Azure CLI on your machine, Install Azure CLI now.
  • Don’t forget to install Azure CLI extensions if you are using for the first time.

The first thing is you need to create the resource group using Azure CLI.

Creating the Resource Group using Azure CLI

You can use the below cmdlet to create a resource group using Azure CLI. That will create the resource group named as Demo906 and the location is eastus.

az group create --name Demo906 --location eastus

Once you will execute the above cmdlet, you will get the output like below

[email protected]:~$ az group create --name Demo906 --location eastus
{
  "id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/Demo906",
  "location": "eastus",
  "managedBy": null,
  "name": "Demo906",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

Creating VNet using Azure CLI

Now, we need to create the virtual network using Azure CLI. Execute the below script to create the virtual network using Azure CLI.

az network vnet create
 --name TSInfoVNet3 --resource-group Demo906 --subnet-name default

Once you will execute the above script, it will create the virtual network named as TSInfoVNet3 with the resource group name as Demo906 and subnet name as default.

You will get the output like below

{
  "newVNet": {
    "addressSpace": {
      "addressPrefixes": [
        "10.0.0.0/16"
      ]
    },
    "bgpCommunities": null,
    "ddosProtectionPlan": null,
    "dhcpOptions": {
      "dnsServers": []
    },
    "enableDdosProtection": false,
    "enableVmProtection": null,
    "etag": "W/\"f1b27aa3-4ff6-484d-b109-a64306bdff6b\"",
    "extendedLocation": null,
    "flowTimeoutInMinutes": null,
    "id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/Demo906/providers/Microsoft.Network/virtualNetworks/TSInfoVNet3",
    "ipAllocations": null,
    "location": "eastus",
    "name": "TSInfoVNet3",
    "provisioningState": "Succeeded",
    "resourceGroup": "Demo906",
    "resourceGuid": "39b01a17-124b-4b6e-a0ab-f2a45ac8ff2b",
    "subnets": [
      {
        "addressPrefix": "10.0.0.0/24",
        "addressPrefixes": null,
        "applicationGatewayIpConfigurations": null,
        "delegations": [],
        "etag": "W/\"f1b27aa3-4ff6-484d-b109-a64306bdff6b\"",
        "id": "/subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/Demo906/providers/Microsoft.Network/virtualNetworks/TSInfoVNet3/subnets/default",
        "ipAllocations": null,
        "ipConfigurationProfiles": null,
        "ipConfigurations": null,
        "name": "default",
        "natGateway": null,
        "networkSecurityGroup": null,
        "privateEndpointNetworkPolicies": "Enabled",
        "privateEndpoints": null,
        "privateLinkServiceNetworkPolicies": "Enabled",
        "provisioningState": "Succeeded",
        "purpose": null,
        "resourceGroup": "Demo906",
        "resourceNavigationLinks": null,
        "routeTable": null,
        "serviceAssociationLinks": null,
        "serviceEndpointPolicies": null,
        "serviceEndpoints": null,
        "type": "Microsoft.Network/virtualNetworks/subnets"
      }
    ],
    "tags": {},
    "type": "Microsoft.Network/virtualNetworks",
    "virtualNetworkPeerings": []
  }
}

This is how to create VNet using Azure CLI.

Delete a virtual network in Azure

Now if you don’t want the VNet anymore and you are actually not using that then in that case, it’s better to delete it.

Before deleting the Virtual Network in Azure, An important point to note down here is, If any resources are connected to that virtual network, you need to delete the resources first before deleting the Virtual Network.

So basically, delete the connected resources first and then delete the virtual network.

Follow the below steps to delete the Virtual Network using the Azure Portal.

  1. Log in to the Azure Portal (https://portal.azure.com/) and search for Virtual networks.
  2. Click on the Search result Virtual networks.
How to Delete a virtual network in Azure

3. Now You can see the list of Virtual Networks you have created. Click the one that you want to delete.

4. On the Virtual Network page, click on the Delete button to delete the VNet.

Delete a virtual network in Azure

5. Finally, click on the Yes button to confirm the deletion.

This is how to delete a virtual network in Azure using Azure Portal.

Azure VNet Peering

  • Azure Virtual network peering is an excellent concept that helps you to connect multiple virtual networks in Azure seamlessly.
  • VNet peering helps you to route the traffic between the virtual networks privately.
  • When there are multple Virtual machines present in peered Virtual networks, the benefit is you they can communicate with each other like they belongs to the same network.

Types of Azure Virtual network peering

There are two types of Azure Virtual network peering available.

  1. Virtual network peering
  2. Global virtual network peering

Virtual network peering

Here, you can connect multiple Azure virtual networks in the same Azure regions.

Global virtual network peering

In the case of Global virtual network peering, you can connect multiple Azure virtual networks across different Azure regions.

Benefits of Azure Virtual network peering

There are some cool benefits that you will get with the use of Azure VNet peering.

  • Your Azure resources will get the provision to communicate with each other seamlessly even though they belong to different networks.
  • The Azure resources those are present in different virtual networks will have high-bandwidth and low-latency rate.
  • While creating the peering, there is no need of any downtime to the Azure resources.
  • Another good thing is, the Azure virtual networks you are going to use for the virtual network peering can belong to either same or different sbscriptions.
  • There is no need of encryption or public internet, etc for the communication between the networks.

Limitations of Azure Virtual network peering

  1. Transitive peering is not supported here. to make it clear let’s consider a scenario, Suppose X has peered with Y, Y has peered with X has not peered with Z.
  2. In case, your virtual networks have matching CIDR blocks then in this scenario, you cannot create the virtual networks peering.

Azure Virtual network peering Pricing

Below is the pricing structure you need to consider if you want to use the Azure virtual network peering.

For the same region

In case the Azure virtual networks belong to the same region, then you need to pay $0.01/GB for inbound data transfer and $0.01/GB for outbound data transfer as well.

For more information, you can check out the Azure Virtual network peering Pricing now.

Azure subnet

  • Subnet is an important concept that you must known while working with virtual networks.
  • The process of deviding a network into small small networks is known as subnet.
  • An Azure subnet is nothing but a range of IP addresses in the Azure virtual network.
  • It’s better to devide a virtual network into multiple subnets in terms of security.
  • It’s all about deviding the IP range of a Virtual network into multiple subnet IP ranges.
  • The Azure resources that are present inside the Azure subnet can communicate with each other and also with the help of Network Security Groups (NSGs), the Azure resources present accross the Azure subnets inside the same Azure virtual network can communicate with each other.
  • The role of the Network Security Groups (NSGs) is quite crucial as it helps to control the traffic from or to the subnets.

You may also like following the below articles

Wrapping Up

Well, in this article, we have discussed  how to create VNet in Azure and along with that we have also discussed the below topics

  • What is vnet in azure
  • How to create a virtual network Azure Portal
  • Create VNet in Azure PowerShell
  • How to create virtual network in Azure using PowerShell
  • Creating VNet using Azure CLI
  • Delete a virtual network in Azure
  • Azure VNet Peering
  • Azure subnet

Hope, you have enjoyed this article !!!