Creating PacktVNet1

To create PacktVNet1, we have to go through the following steps:

  1. First, we need to log in to the Azure account:
Connect-AzAccount
  1. If necessary, select the right subscription:
Select-AzSubscription -SubscriptionId "********-****-****-****-***********"
  1. Define the variables for the first VNet:
$RG1 = "PacktResourceGroup1"
$Location1 = "East US"
$VNetName1 = "PacktVNet1"
$FESubName1 = "FrontEnd"
$BESubName1 = "Backend"
$VNetPrefix01 = "10.11.0.0/16"
$VNetPrefix02 = "10.12.0.0/16"
$FESubPrefix1 = "10.11.0.0/24"
$BESubPrefix1 = "10.12.0.0/24"
$GWSubPrefix1 = "10.12.255.0/27"
$GWName1 = "PacktVNet1Gateway"
$GWIPName1 = "PacktVNet1GWIP"
$GWIPconfName1 = "gwipconf1"
$Connection01 = "VNet1toVNet2"
  1. Create a resource group:
New-AzResourceGroup -Name $RG1 -Location $Location1
  1. Create subnet configurations for PacktVNet1. In this demonstration, we are going to create a VNet, called PacktVNet1, and three subnets, called FrontEnd, Backend, and GatewaySubnet. It is important to name your gateway subnet GatewaySubnet; otherwise, the gateway creation will fail.

It is recommended that you create a gateway subnet using a /27. This includes more addresses, which will accommodate possible additional configurations that you may want to make in the future:

$fesub1 = New-AzVirtualNetworkSubnetConfig -Name $FESubName1 -AddressPrefix $FESubPrefix1
$besub1 = New-AzVirtualNetworkSubnetConfig -Name $BESubName1 -AddressPrefix $BESubPrefix1
$gwsub1 = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -
AddressPrefix $GWSubPrefix1
  1. Create PacktVNet1:
New-AzVirtualNetwork -Name $VNetName1 `
-ResourceGroupName $RG1 `
-Location $Location1 `
-AddressPrefix $VNetPrefix01,$VNetPrefix02 `
-Subnet $fesub1,$besub1,$gwsub1
  1. Request a public IP address to be allocated to the gateway that you will create for PacktVNet1. Here, you cannot specify the IP address that you want to use. It's dynamically allocated to your gateway:
$gwpip1 = New-AzPublicIpAddress `
-Name $GWIPName1 `
-ResourceGroupName $RG1 `
-Location $Location1 `
-AllocationMethod Dynamic
  1. Create the gateway configuration. The gateway configuration defines the subnet and the public IP address to use: 
$vnet1 = Get-AzVirtualNetwork `
-Name $VNetName1 `
-ResourceGroupName $RG1
$subnet1 = Get-AzVirtualNetworkSubnetConfig `
-Name "GatewaySubnet" `
-VirtualNetwork $vnet1
$gwipconf1 = New-AzVirtualNetworkGatewayIpConfig `
-Name $GWIPconfName1 `
-Subnet $subnet1 `
-PublicIpAddress $gwpip1
  1. Create the gateway for PacktVNet1. VNet-to-VNet configurations require a RouteBased setting for VpnType:
New-AzVirtualNetworkGateway `
-Name $GWName1 `
-ResourceGroupName $RG1 `
-Location $Location1 `
-IpConfigurations $gwipconf1 `
-GatewayType Vpn `
-VpnType RouteBased `
-GatewaySku VpnGw1
 Creating a gateway can often take 45 minutes or more, depending on the selected gateway SKU. The different gateway SKUs are covered in more detail in Chapter 11, Integrating On-Premises Networks with Azure Virtual Networks.

We have now created the first VNet. In the next section, we are going to create PacktVNet2.

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

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