How To Create VNet In Azure

How To Create Vnet In Azure

This Azure tutorial will discuss how to create VNet in Azure.

How To Create VNet In Azure

Before discussing how to create a VNet in Azure, we should have a basic idea of what a VNet is in Azure. Then, we will discuss the prerequisites for VNet creation in Azure and the steps.

Prerequisites

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

How to create a VNet in Azure

It’s quite easy to create a virtual network 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

You can also click on the + Create a resource option at the top left corner of the Azure Portal to access the same steps.

create virtual network in azure

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

create a vnet using vnet services (assuming required parameters)

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 create a new one using the Create new link.
  • Name: Provide a name for the virtual network.
  • Region: Select the Region.

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

how to create virtual network in azure

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

azure vnet

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

create a virtual network in azure

Create VNet in Azure using PowerShell

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

Prerequisites

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

  • You must have an Azure account or Azure Subscription. If you haven’t had it till now, create an Azure Free Account.
  • You must install the latest version of Azure Power Shell on your machine. If you have not yet installed it, Install Azure PowerShell now.

The first step is to create a resource group. The resource group will be responsible for hosting the virtual network.

Creating a resource group using PowerShell

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

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

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

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

You can check it out below

create a virtual network in azure

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

Now is 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 run the above script, the 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 was created successfully.

create azure vnet

Now, the next step is to add a subnet.

Adding a subnet

You can use the Azure PowerShell script below 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 execute the above PowerShell cmdlet, you will get the output 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

Create VNet In Azure CLI

We have already discussed 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 to create the virtual network using Azure CLI.

  • You must have an Azure account or Azure Subscription. If you haven’t had it till now, create an Azure Free Account.
  • 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 use them for the first time.

First, you must 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 Demo906, and the location is east of us.

az group create --name Demo906 --location eastus

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

bijay@Azure:~$ 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 execute the above script, it will create the virtual network named TSInfoVNet3 with the resource group name Demo906 and subnet name as default.

You will get the output 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. If you don’t want the VNet anymore, you can delete the Virtual Network.

FAQs

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 you create.

For higher security, you can divide a VNet into multiple subnets.

This is a small introduction to the VNet in Azure. Now, assuming you have a bit of an idea of what a VNet in Azure is, let’s discuss the prerequisites needed to create one.

What is Azure subnet?

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

You may also like following the articles below

Wrapping Up

Well, in this article, we have discussed  how to create a VNet in Azure. I hope, you have enjoyed this article !!!