Share via


Create a virtual network (classic) by using the Azure CLI

Important

Classic Virtual Network is now deprecated for new customers and will be retired on August 31st, 2024 for all customers. New deployments should use the new Azure Resource Manager based deployment model Azure Resource Manager based Virtual Network

An Azure virtual network (VNet) is a representation of your own network in the cloud. You can control your Azure network settings and define DHCP address blocks, DNS settings, security policies, and routing. You can also further segment your VNet into subnets and deploy Azure IaaS virtual machines (VMs) and PaaS role instances, in the same way you can deploy physical and virtual machines to your on-premises datacenter. In essence, you can expand your network to Azure, bringing your own IP address blocks. Read the virtual network overview if you are not familiar with VNets.

Important

Before you work with Azure resources, it's important to understand that Azure currently has two deployment models: Azure Resource Manager and classic. Make sure you understand deployment models and tools before you work with any Azure resource. You can view the documentation for different tools by clicking the tabs at the top of this article.

This document covers creating a VNet by using the classic deployment model. You can also create a virtual network in the Resource Manager deployment model by using the Azure CLI.

Scenario

To illustrate how to create a VNet and subnets, this document uses the following scenario:

VNet scenario

In this scenario you create a VNet named TestVNet, with a reserved CIDR block of 192.168.0.0./16. The VNet contains the following subnets:

  • FrontEnd, using 192.168.1.0/24 as its CIDR block.
  • BackEnd, using 192.168.2.0/24 as its CIDR block.

How to create a classic VNet using Azure CLI

You can use the Azure CLI to manage your Azure resources from the command prompt from any computer running Windows, Linux, or OSX.

  1. If you have never used Azure CLI, see Install and Configure the Azure CLI and follow the instructions up to the point where you select your Azure account and subscription.

  2. To create a VNet and a subnet, run the azure network vnet create command:

         azure network vnet create --vnet TestVNet -e 192.168.0.0 -i 16 -n FrontEnd -p 192.168.1.0 -r 24 -l "Central US"
    

    Expected output:

         info:    Executing command network vnet create
         + Looking up network configuration
         + Looking up locations
         + Setting network configuration
         info:    network vnet create command OK
    
    • --vnet. Name of the VNet to be created. For the scenario, TestVNet
    • -e (or --address-space). VNet address space. For the scenario, 192.168.0.0
    • -i (or -cidr). Network mask in CIDR format. For the scenario, 16.
    • -n (or --subnet-name). Name of the first subnet. For the scenario, FrontEnd.
    • -p (or --subnet-start-ip). Starting IP address for subnet, or subnet address space. For the scenario, 192.168.1.0.
    • -r (or --subnet-cidr). Network mask in CIDR format for subnet. For the scenario, 24.
    • -l (or --location). Azure region where the VNet is created. For the scenario, Central US.
  3. To create a subnet, run the azure network vnet subnet create command:

         azure network vnet subnet create -t TestVNet -n BackEnd -a 192.168.2.0/24
    

    The expected output for the previous command:

         info:    Executing command network vnet subnet create
         + Looking up network configuration
         + Creating subnet "BackEnd"
         + Setting network configuration
         + Looking up the subnet "BackEnd"
         + Looking up network configuration
         data:    Name                            : BackEnd
         data:    Address prefix                  : 192.168.2.0/24
         info:    network vnet subnet create command OK
    
    • -t (or --vnet-name. Name of the VNet where the subnet will be created. For the scenario, TestVNet.
    • -n (or --name). Name of the new subnet. For the scenario, BackEnd.
    • -a (or --address-prefix). Subnet CIDR block. For the scenario, 192.168.2.0/24.
  4. To view the properties of the new vnet, run the azure network vnet show command:

         azure network vnet show
    

    Expected output for the previous command:

         info:    Executing command network vnet show
         Virtual network name: TestVNet
         + Looking up the virtual network sites
         data:    Name                            : TestVNet
         data:    Location                        : Central US
         data:    State                           : Created
         data:    Address space                   : 192.168.0.0/16
         data:    Subnets:
         data:      Name                          : FrontEnd
         data:      Address prefix                : 192.168.1.0/24
         data:
         data:      Name                          : BackEnd
         data:      Address prefix                : 192.168.2.0/24
         data:
         info:    network vnet show command OK