Skip to content

Latest commit

 

History

History
62 lines (50 loc) · 2.17 KB

azure-cli-vm-tutorial-2.md

File metadata and controls

62 lines (50 loc) · 2.17 KB
title description ms.date manager author ms.author ms.tool ms.topic ms.service ms.custom keywords
Create virtual network (VNet) – Azure CLI | Microsoft Docs
Learn how to create a virtual network (VNet) and subnet with the Azure CLI.
01/08/2024
jasongroce
dbradish-microsoft
dbradish
azure-cli
tutorial
azure-cli
devx-track-azurecli, seo-azure-cli
azure cli create vnet, virtual network in azure cli, subnet in virtual network

Create a virtual network

Virtual networks (VNets) allow virtual machines (VMs) and other Azure resources to communicate securely with each other, the internet, and on-premises networks. VNets can also be connected to other VNets if their address ranges don't overlap. In this section, you learn how to create a virtual network with a subnet.

Subnets allow you to segment the VNet address space into subnetworks for organization purposes. Azure deploys resources to subnets within a virtual network, so you need to create a subnet.

Use the az network vnet create command to create a virtual network named TutorialVNet1 with address prefix of 10.0.0.0/16 and a subnet named TutorialSubnet1 with address prefix of 10.0.0.0/24.

# create Bash shell variables
vnetName=TutorialVNet1
subnetName=TutorialSubnet1
vnetAddressPrefix=10.0.0.0/16
subnetAddressPrefix=10.0.0.0/24

# Use the existing resource group
resourceGroup=VMTutorialResources

az network vnet create \
  --name $vnetName \
  --resource-group $resourceGroup \
  --address-prefixes $vnetAddressPrefix \
  --subnet-name $subnetName \
  --subnet-prefixes $subnetAddressPrefix
# create PowerShell variables
$vnetName = "TutorialVNet1"
$subnetName = "TutorialSubnet1"
$vnetAddressPrefix = "10.0.0.0/16"
$subnetAddressPrefix = "10.0.0.0/24"

# Use the existing resource group
$resourceGroup = "VMTutorialResources"

# Create a virtual network and subnet
az network vnet create `
  --name $vnetName `
  --resource-group $resourceGroup `
  --address-prefixes $vnetAddressPrefix `
  --subnet-name $subnetName `
  --subnet-prefixes $subnetAddressPrefix