Create a Virtual Network (VNet) in Azure
This guide provides step-by-step instructions on how to create a new Azure Virtual Network (VNet) using the Azure portal, Azure CLI, and Azure PowerShell.
Important:
A VNet is a fundamental building block for your private network in Azure. It allows Azure resources to communicate with each other, with the internet, and with your on-premises networks. Properly planning your VNet address space and subnets is crucial for scalability and security.
Method 1: Using the Azure Portal
The Azure portal offers a user-friendly graphical interface for creating VNets.
Step 1: Sign in to the Azure portal
Open your web browser and navigate to https://portal.azure.com/. Sign in with your Azure account credentials.
Step 1: Navigate to Virtual Networks
In the Azure portal, click on the + Create a resource button in the upper-left corner. Search for Virtual Network and select it. Then, click Create.
Step 3: Configure the Virtual Network basics
- Subscription: Select your Azure subscription.
- Resource group: Create a new resource group or select an existing one.
- Name: Enter a unique name for your virtual network (e.g.,
myVNet). - Region: Choose the Azure region where you want to deploy your VNet.
Step 4: Configure IP Addresses
- IPv4 address space: Define the address space for your VNet. For example,
10.0.0.0/16. Ensure this range does not overlap with your on-premises networks or other VNets. - Subnets: Click Add subnet to define your first subnet.
- Name: Enter a name for your subnet (e.g.,
default). - Address range: Specify a smaller range within the VNet's address space (e.g.,
10.0.0.0/24).
- Name: Enter a name for your subnet (e.g.,
Tip:
It's a best practice to create multiple subnets for different workloads or security zones within your VNet.
Step 5: Configure Security (Optional)
You can configure options like Service endpoints, Firewall, or DDoS protection here, or configure them later.
Step 6: Tags (Optional)
Add tags to categorize your resources for better management.
Step 7: Review and Create
Click Review + create. Azure will validate your configuration. Once validation passes, click Create.
Method 2: Using Azure CLI
Use the Azure Command-Line Interface for scripting and automation.
First, ensure you have Azure CLI installed and are logged in:
az login
Create a resource group (if you don't have one):
az group create --name myResourceGroup --location eastus
Create the virtual network and a default subnet:
az network vnet create \
--resource-group myResourceGroup \
--name myVNet \
--address-prefix 10.1.0.0/16 \
--subnet-name subnet1 \
--subnet-prefix 10.1.0.0/24
Method 3: Using Azure PowerShell
Use Azure PowerShell for managing Azure resources programmatically.
First, ensure you have Azure PowerShell installed and are logged in:
Connect-AzAccount
Create a resource group (if you don't have one):
New-AzResourceGroup -Name "myResourceGroup" -Location "East US"
Create the virtual network and a default subnet:
$vnet = New-AzVirtualNetwork `
-ResourceGroupName "myResourceGroup" `
-Location "East US" `
-Name "myVNet" `
-AddressPrefix "10.2.0.0/16"
$subnet = Add-AzVirtualNetworkSubnetConfig `
-Name "subnet1" `
-AddressPrefix "10.2.0.0/24" `
-VirtualNetwork $vnet
$vnet | Set-AzVirtualNetwork
Next Steps:
Once your VNet is created, you can proceed to create subnets, deploy virtual machines, configure network security groups, and set up connections to other networks.