This post is part of a series in which I will show how to create different resources in Microsoft Azure. Today I will show you how to create an essential component: a Virtual Network.

A virtual network enables many types of Azure resources to communicate privately with each other, and with the internet.

This tutorial assumes that you already have a Microsoft Azure account set up.

Azure PowerShell Workaround

If you want to know how to install the PowerShell Azure module on your machine, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.
If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task we will use the following commands:

Once you set your default subscription, you are ready to create a Virtual Network with New-AzureRmVirtualNetwork cmdlet.

new-azurermvirtualnetwork

To create a Virtual Network with PowerShell, use the New-AzureRmVirtualNetwork cmdlet with the following syntax:

new-azurermvirtualnetwork

Parameters

-Name

Specify a representative name of the virtual network.

-ResourceGroupName 

With the following command in PowerShell, we obtain the list of existing resource groups in your subscription.

Get-AzureRmResourceGroup

If you need to create a new resource group, check out this link.

-Location 

With the following cmdlet in PowerShell, we obtain the list of existing locations in Azure.

-AddressPrefix

Specify an IP Address Range.

Subnets

Once you have created your virtual network, you must create one or more subnets for your virtual network. When you segment a virtual network, you are dividing it into smaller network segments. Basically, groups of systems or resources are separating from each other.

To create a Virtual Subnet with PowerShell, use the Add-AzureRmVirtualNetworkSubnetConfig cmdlet with the following syntax:

Add-AzureRmVirtualNetworkSubnetConfig

Parameters

-Name

  • Must be unique within the virtual network

-AddressPrefix

  • Must be unique within the address space for the virtual network.
  • Cannot overlap with other subnet address ranges within the virtual network.

With the Set-AzureRmVirtualNetwork cmdlet set the subnet configuration in the virtual network.

set-azurermvirtualnetwork

Azure CLI Workaround

You can use it in your browser with Azure Cloud Shell, or install it on your machine. If you want to know how to install the Azure CLI, check out this link.
The way to get started is to sign in interactively at the command line.

This command will bring up a dialog box prompting you for your email address and password associated with your Azure account.

If you have more than one subscription associated with your mail account, you can choose the default subscription. to perform this task we will use the following commands:

To create a Virtual Network with Azure CLI, use the following syntax:

az network vnet create

Parameters

–name

Specify a representative name of the virtual network.

–resource-group 

With the following command in Azure CLI, we obtain the list of existing resource groups in your subscription.

To create a new resource group with Azure CLI, check out this link.

–location 

With the following command, we obtain the list of existing locations in Azure.

–address-prefixes

Specify an IP Address Range.

–subnet-name

Specify a name for the subnet. The subnet name must be unique within the virtual network.

–subnet-prefix

The range of IP addresses for a subnet must be unique within the address space for the virtual network and cannot overlap with other subnet address ranges within the virtual network.

As you can see in the screenshot, you can use the online command help with the –help or -h parameter.

az network vnet create

You can check the task by running the following command, the -g parameter indicates the Resource Group:

If you want to know more about Virtual Network, check out this link:https://docs.microsoft.com/en-us/azure/virtual-network/