Creating PacktVNet2

To create PacktVNet2, we have to take the following steps:

  1. Define the variables for the first VNet:
$RG2 = "PacktResourceGroup2"
$Location2 = "West US"
$VNetName2 = "PacktVNet2"
$FESubName2 = "FrontEnd"
$BESubName2 = "Backend"
$VnetPrefix11 = "10.41.0.0/16"
$VnetPrefix12 = "10.42.0.0/16"
$FESubPrefix2 = "10.41.0.0/24"
$BESubPrefix2 = "10.42.0.0/24"
$GWSubPrefix2 = "10.42.255.0/27"
$GWName2 = "PacktVNet2Gateway"
$GWIPName2 = "PacktVNet1GWIP"
$GWIPconfName2 = "gwipconf2"
$Connection2 = "VNet2toVNet1"
  1. Create a resource group:
New-AzResourceGroup -Name $RG2 -Location $Location2
  1. Create subnet configurations for PacktVNet2:
$fesub2 = New-AzVirtualNetworkSubnetConfig -Name $FESubName2 -AddressPrefix $FESubPrefix2
$besub2 = New-AzVirtualNetworkSubnetConfig -Name $BESubName2 -AddressPrefix $BESubPrefix2
$gwsub2 = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix $GWSubPrefix2
  1. Create PacktVNet2:
New-AzVirtualNetwork `
-Name $VnetName2 `
-ResourceGroupName $RG2 `
-Location $Location2 `
-AddressPrefix $VnetPrefix11,$VnetPrefix12 `
-Subnet $fesub2,$besub2,$gwsub2
  1. Request a public IP address:
$gwpip2 = New-AzPublicIpAddress `
-Name $GWIPName2 `
-ResourceGroupName $RG2 `
-Location $Location2 `
-AllocationMethod Dynamic
  1. Create the gateway configuration:
$vnet2 = Get-AzVirtualNetwork `
-Name $VnetName2 `
-ResourceGroupName $RG2
$subnet2 = Get-AzVirtualNetworkSubnetConfig `
-Name "GatewaySubnet" `
-VirtualNetwork $vnet2
$gwipconf2 = New-AzVirtualNetworkGatewayIpConfig `
-Name $GWIPconfName2 `
-Subnet $subnet2 `
-PublicIpAddress $gwpip2
  1. Create the gateway:
New-AzVirtualNetworkGateway -Name $GWName2 `
-ResourceGroupName $RG2 `
-Location $Location2 `
-IpConfigurations $gwipconf2 `
-GatewayType Vpn `
-VpnType RouteBased `
-GatewaySku VpnGw1

Wait for the gateway to be created. After its creation, we can create connections between the VNets.

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

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