Hi fellows,

Virtual Network in Azure is core of Infrastructure-as-a-Service. Without virtual network, you cannot do anything with Azure virtual machines and if you haven’t created virtual network and subnets, virtual machine creating process wizard will create virtual network for virtual machine. But in the most of the cases, you should create virtual network and subnets before you start to provision virtual machines and other resources.

Although Virtual Network, like as all other resources, can be created using Azure Portal, PowerShell, CLI, ARM, and many other ways, in this post, I will show you how you can do that using Azure portal and Azure PowerShell.

If you decide to use Azure portal, you need to click to Create a resource in left menu and select Virtual Network, like on image below.

Once you find Virtual Network resource in marketplace, you need to select resource for deployment.

When creating wizard is opened, you just need to fill in the required fields with appropriate parameters.

  • Name of virtual network
  • Address spaceNeeds to be with lower prefix than the subnets
  • Resource groupDefine where the virtual network resource will be created
  • LocationLocation of virtual network resource is important for further use
  • Subnet name
  • Subnet address rangeNeeds to be under virtual network address space

If you want to use PowerShell to configure virtual network with one subnet in new resource group, you need to run following script.

# Define variables
$Location            = 'North Europe'
$RGName              = "TechTrainer-Networking"
$VirtualNetworkName  = "TechTrainer-vNet"
$vNetAddressPrefix   = ""
$SubnetName          = "DefaultSubnet" # Define subnet name per your organization needs
$SubnetAddressPrefix = ""

# Create a resource group for networking resources
New-AzResourceGroup -Name $RGName -Location $Location

# Create a virtual network
$VirtualNetwork = New-AzVirtualNetwork -ResourceGroupName $RGName -Location $Location -Name $VirtualNetworkName -AddressPrefix $vNetAddressPrefix

# Create a subnet configuration
$SubnetConfig = Add-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix -VirtualNetwork $virtualNetwork

# Set the subnet configuration for the virtual network
$VirtualNetwork | Set-AzVirtualNetwork

Once you have configured virtual network and subnet, you can start with provisioning virtual machines and other resources.


Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.