0
0
Azurecloud~5 mins

VNet creation and address space in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
A Virtual Network (VNet) lets you create a private network in the cloud. It helps you control how your cloud resources communicate securely by defining address spaces and subnets.
When you want to isolate your cloud resources from the public internet.
When you need to connect multiple cloud services securely within the same network.
When you want to define IP address ranges for your cloud resources to avoid conflicts.
When you plan to connect your cloud network to your on-premises network.
When you want to control traffic flow between different parts of your cloud environment.
Config File - vnet-template.json
vnet-template.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2022-07-01",
      "name": "example-vnet",
      "location": "eastus",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "10.0.0.0/16"
          ]
        },
        "subnets": [
          {
            "name": "default",
            "properties": {
              "addressPrefix": "10.0.0.0/24"
            }
          }
        ]
      }
    }
  ]
}

This JSON file is an Azure Resource Manager (ARM) template that creates a Virtual Network named example-vnet in the eastus region.

The addressSpace defines the IP range 10.0.0.0/16 for the whole network.

The subnets section creates one subnet named default with the IP range 10.0.0.0/24 inside the VNet.

Commands
This command creates a resource group named example-resource-group in the eastus region. Resource groups hold related cloud resources together.
Terminal
az group create --name example-resource-group --location eastus
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-resource-group", "location": "eastus", "managedBy": null, "name": "example-resource-group", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Specifies the name of the resource group
--location - Specifies the Azure region for the resource group
This command deploys the ARM template file vnet-template.json to create the Virtual Network inside the example-resource-group.
Terminal
az deployment group create --resource-group example-resource-group --template-file vnet-template.json
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentName", "name": "deploymentName", "properties": { "provisioningState": "Succeeded", "outputs": {} } }
--resource-group - Specifies the resource group to deploy the template
--template-file - Specifies the ARM template file to use for deployment
This command shows details of the Virtual Network named example-vnet to verify it was created with the correct address space.
Terminal
az network vnet show --resource-group example-resource-group --name example-vnet
Expected OutputExpected
{ "addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] }, "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-resource-group/providers/Microsoft.Network/virtualNetworks/example-vnet", "location": "eastus", "name": "example-vnet", "properties": { "subnets": [ { "addressPrefix": "10.0.0.0/24", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-resource-group/providers/Microsoft.Network/virtualNetworks/example-vnet/subnets/default", "name": "default" } ] }, "resourceGroup": "example-resource-group", "type": "Microsoft.Network/virtualNetworks" }
--resource-group - Specifies the resource group containing the VNet
--name - Specifies the name of the VNet to show
Key Concept

If you remember nothing else from this pattern, remember: defining the address space correctly when creating a VNet controls how your cloud resources communicate privately.

Common Mistakes
Using overlapping IP address ranges in multiple VNets or subnets
This causes IP conflicts and prevents proper communication between resources.
Plan and assign unique, non-overlapping IP address ranges for each VNet and subnet.
Not specifying the correct resource group when deploying the template
The deployment will fail or create resources in an unintended group, causing confusion.
Always use the correct resource group name with --resource-group flag during deployment.
Forgetting to verify the VNet creation after deployment
You might miss errors or misconfigurations that affect your network setup.
Run az network vnet show to confirm the VNet and its address space are correct.
Summary
Create a resource group to hold your cloud resources using az group create.
Deploy an ARM template defining the VNet and its address space with az deployment group create.
Verify the VNet creation and address space using az network vnet show.