1 minute reading time
(174 words)
Create Virtual Network and subnet using Azure CLI
How to create a Virtual Network and subnet using Azure CLI
Create resource group using az group create
# Define resource group variables for name and location rgName=prod-ukw-core-rg rgLocation=ukwest # Create resource group and output results in a table az group create --name $rgName --location $rgLocation --output table
Create virtual network and subnet using az network vnet create
This example will create a VNet with an address space of 192.168.2.0/24 and a subnet of 192.168.2.0/27, which will allow 27 usable IP addresses.
If you don't specify the VNet address space, the new VNet will be created using the default address space 10.0.0.0/16 and the subnet will be created using 10.0.0.0/24
# Define vnet variables VnetName=prod-ukw-core-vnet RgName=prod-ukw-core-rg SubnetName=subnet01 AddressPrefix=192.168.2.0/24 SubnetPrefix=192.168.2.0/27 az network vnet create \ --name $VnetName \ --resource-group $RgName \ --subnet-name $SubnetName \ --address-prefix $AddressPrefix \ --subnet-prefix $SubnetPrefix
New VNet has been created with address space 192.168.2.0/24 and subnet 192.168.2.0/27
Reference:
Azure CLI - az network vnet create
by Author
https://docs.microsoft.com/en-us/cli/azure/network/vnet?view=azure-cli-latest#az-network-vnet-create
Comments