Configuring virtual networks and subnets

In this section, we are going to create and configure a virtual network and a subnet from the Azure portal. We created both of these in earlier demonstrations, for instance, when we created VMs. Now, we are going to cover this topic in more detail.

Here, we are going to configure a virtual network and a subnet using PowerShell. Therefore, we have to perform the following steps:

  1. First, we need to log into our Azure account, as follows:
Connect-AzAccount
  1. If necessary, select the right subscription, as follows:
Select-AzSubscription -SubscriptionId "********-****-****-****-***********"
  1. Create a resource group for the VNet as follows:
New-AzResourceGroup -Name PacktVNetResourceGroup -Location EastUS

  1. Next, we can create the VNet, as follows:
$virtualNetwork = New-AzVirtualNetwork `
-ResourceGroupName PacktVNetResourceGroup `
-Location EastUS `
-Name PacktVirtualNetwork `
-AddressPrefix 10.0.0.0/16
  1. Then, we can create the subnet, as follows:
$subnetConfig = Add-AzVirtualNetworkSubnetConfig `
-Name default `
-AddressPrefix 10.0.0.0/24 `
-VirtualNetwork $virtualNetwork
  1. Finally, we can associate the subnet with the virtual network, as follows:
$virtualNetwork | Set-AzVirtualNetwork

Now, we have created a VNet and a subnet from PowerShell. We will use this for further demonstration purposes in this chapter. In the next section, we are going to configure both a private and a public IP address in PowerShell and associate them with this VNet.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset