How to create a Virtual Network in Microsoft Azure

Jorge Bernhardt
Cloud Computing
June 10, 2020

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.

 
  
Login-AzureRmAccount
 

 

 

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:

 
  
Get-AzureRmSubscription
Select-AzureRmSubscription -Subscription "My Subscription"
 

 

 

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 -Name  `
                          -ResourceGroupName  `
                          -Location  `
                          -AddressPrefix 

 

 

 

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 | Select-Object ResourceGroupName, Location
 

 

 

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.

 
  
Get-AzureRmLocation | Select-Object DisplayName, Location
 

 

 

-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:

 
  
$vnet = Get-AzureRmVirtualNetwork -Name  - ResourceGroupName 
Add-AzureRmVirtualNetworkSubnetConfig -Name  `
                                      -VirtualNetwork  `
                                      -AddressPrefix 

 

 

 

 

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.

 
  
$vnet | Set-AzureRmVirtualNetwork
 

 

 

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.

 
  
az login
 

  

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:

 
  
az account list
az account set --subscription "Subscription Name"
 

 

 

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

 
  
az network vnet create --name VNet-Demo \
                   	--resource-group RG-CLI \
                   	--location westeurope \
                   	--address-prefixes 192.168.0.0/16 \
                   	--subnet-name Subnet-01 \
                   	--subnet-prefix 192.168.1.0/24
 

 

 

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.

 
  
az group list
 

  

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.

 
  
az account list-locations
 

  

–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:

 
  
az network vnet list -g RG-CLI
 

  

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


Jorge Bernhardt

Hi! I am Jorge Bernhardt and I have been an IT professional for almost 20 years. During this time, I have worked as a helpdesk operator, systems administrator, and cloud architect. I am specialised in Microsoft Technologies, particularly Microsoft Cloud & Datacenter solutions, Microsoft Virtualisation, and Microsoft 365. I love learning from other professionals and, when possible, share my knowledge back with the community.

https://www.jorgebernhardt.com

Keep Reading

Newsletter EuropeClouds.com

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form