0
0
AzureHow-ToBeginner · 3 min read

How to Create a Virtual Network (VNet) in Azure Easily

To create a Virtual Network (VNet) in Azure, use the az network vnet create command with parameters for resource group, VNet name, address prefix, and location. This sets up a private network space for your Azure resources to communicate securely.
📐

Syntax

The basic command to create a VNet in Azure CLI is:

az network vnet create --resource-group <resource-group-name> --name <vnet-name> --address-prefix <address-prefix> --location <location>

Explanation of parts:

  • --resource-group: The name of your Azure resource group where the VNet will be created.
  • --name: The name you want to give your VNet.
  • --address-prefix: The IP address range for the VNet in CIDR notation (e.g., 10.0.0.0/16).
  • --location: The Azure region where the VNet will be deployed (e.g., eastus).
bash
az network vnet create --resource-group MyResourceGroup --name MyVNet --address-prefix 10.0.0.0/16 --location eastus
💻

Example

This example creates a VNet named MyVNet in the resource group MyResourceGroup with the address space 10.0.0.0/16 in the eastus region.

bash
az group create --name MyResourceGroup --location eastus
az network vnet create --resource-group MyResourceGroup --name MyVNet --address-prefix 10.0.0.0/16 --location eastus
Output
{ "newVNet": { "addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] }, "location": "eastus", "name": "MyVNet", "resourceGroup": "MyResourceGroup", "provisioningState": "Succeeded", "type": "Microsoft.Network/virtualNetworks" } }
⚠️

Common Pitfalls

  • Forgetting to create the resource group before creating the VNet causes errors.
  • Using overlapping or invalid IP address ranges can cause conflicts.
  • Not specifying the location or using a different location than the resource group can cause deployment failures.
  • Using an existing VNet name in the same resource group will fail.
bash
## Wrong: Creating VNet without resource group
az network vnet create --resource-group MissingGroup --name MyVNet --address-prefix 10.0.0.0/16 --location eastus

## Right: Create resource group first
az group create --name MissingGroup --location eastus
az network vnet create --resource-group MissingGroup --name MyVNet --address-prefix 10.0.0.0/16 --location eastus
📊

Quick Reference

Remember these key points when creating a VNet:

  • Always create or use an existing resource group first.
  • Choose a unique VNet name within the resource group.
  • Use valid CIDR notation for --address-prefix.
  • Match the --location with your resource group location.

Key Takeaways

Use az network vnet create with resource group, name, address prefix, and location to create a VNet.
Always create the resource group before creating the VNet to avoid errors.
Use valid, non-overlapping IP address ranges in CIDR format for the VNet.
Ensure the VNet name is unique within the resource group.
Match the location of the VNet with the resource group's location.