Before creating a virtual network, you have to create a resource group for the virtual network, and all other resources created in this article. Create a resource group with New-AzResourceGroup. The following example creates a resource group named test-rg in the eastus location.
$resourceGroup = @{
Name = "test-rg"
Location = "EastUS2"
}
New-AzResourceGroup @resourceGroup
Create a virtual network with New-AzVirtualNetwork. The following example creates a virtual network named vnet-1 with the address prefix 10.0.0.0/16.
$vnet1 = @{
ResourceGroupName = "test-rg"
Location = "EastUS2"
Name = "vnet-1"
AddressPrefix = "10.0.0.0/16"
}
$virtualNetwork1 = New-AzVirtualNetwork @vnet1
Create a subnet configuration with Add-AzVirtualNetworkSubnetConfig. The following example creates a subnet configuration with a 10.0.0.0/24 address prefix:
$subConfig = @{
Name = "subnet-1"
AddressPrefix = "10.0.0.0/24"
VirtualNetwork = $virtualNetwork1
}
$subnetConfig1 = Add-AzVirtualNetworkSubnetConfig @subConfig
Create a subnet configuration for Azure Bastion with Add-AzVirtualNetworkSubnetConfig. The following example creates a subnet configuration with a 10.0.1.0/24 address prefix:
$subBConfig = @{
Name = "AzureBastionSubnet"
AddressPrefix = "10.0.1.0/24"
VirtualNetwork = $virtualNetwork1
}
$subnetConfig2 = Add-AzVirtualNetworkSubnetConfig @subBConfig
Write the subnet configuration to the virtual network with Set-AzVirtualNetwork, which creates the subnet:
$virtualNetwork1 | Set-AzVirtualNetwork
Create a public IP address for the Azure Bastion host with New-AzPublicIpAddress. The following example creates a public IP address named public-ip-bastion in the vnet-1 virtual network.
$publicIpParams = @{
ResourceGroupName = "test-rg"
Name = "public-ip-bastion"
Location = "EastUS2"
AllocationMethod = "Static"
Sku = "Standard"
}
New-AzPublicIpAddress @publicIpParams
Create an Azure Bastion host with New-AzBastion. The following example creates an Azure Bastion host named bastion in the AzureBastionSubnet subnet of the vnet-1 virtual network. Azure Bastion is used to securely connect Azure virtual machines without exposing them to the public internet.
$bastionParams = @{
ResourceGroupName = "test-rg"
Name = "bastion"
VirtualNetworkName = "vnet-1"
PublicIpAddressName = "public-ip-bastion"
PublicIpAddressRgName = "test-rg"
VirtualNetworkRgName = "test-rg"
}
New-AzBastion @bastionParams -AsJob
Create a second virtual network
Create a second virtual network with New-AzVirtualNetwork. The following example creates a virtual network named vnet-2 with the address prefix 10.1.0.0/16.
Note
The second virtual network can be in the same region as the first virtual network or in a different region. You don't need a Bastion deployment for the second virtual network. After the network peer, you can connect to both virtual machines with the same Bastion deployment.
$vnet2 = @{
ResourceGroupName = "test-rg"
Location = "EastUS2"
Name = "vnet-2"
AddressPrefix = "10.1.0.0/16"
}
$virtualNetwork2 = New-AzVirtualNetwork @vnet2
Create a subnet configuration with Add-AzVirtualNetworkSubnetConfig. The following example creates a subnet configuration with a 10.1.0.0/24 address prefix:
$subConfig = @{
Name = "subnet-1"
AddressPrefix = "10.1.0.0/24"
VirtualNetwork = $virtualNetwork2
}
$subnetConfig = Add-AzVirtualNetworkSubnetConfig @subConfig
Write the subnet configuration to the virtual network with Set-AzVirtualNetwork, which creates the subnet:
$virtualNetwork2 | Set-AzVirtualNetwork
Before creating a virtual network, you have to create a resource group for the virtual network, and all other resources created in this article. Create a resource group with az group create. The following example creates a resource group named test-rg in the eastus location.
az group create \
--name test-rg \
--location eastus2
Create a virtual network with az network vnet create. The following example creates a virtual network named vnet-1 with the address prefix 10.0.0.0/16.
az network vnet create \
--name vnet-1 \
--resource-group test-rg \
--address-prefixes 10.0.0.0/16 \
--subnet-name subnet-1 \
--subnet-prefix 10.0.0.0/24
Create the Bastion subnet with az network vnet subnet create.
az network vnet subnet create \
--vnet-name vnet-1 \
--resource-group test-rg \
--name AzureBastionSubnet \
--address-prefix 10.0.1.0/24
Create a public IP address for the Azure Bastion host with az network public-ip create. The following example creates a public IP address named public-ip-bastion in the vnet-1 virtual network.
az network public-ip create \
--resource-group test-rg \
--name public-ip-bastion \
--location eastus2 \
--allocation-method Static \
--sku Standard
Create an Azure Bastion host with az network bastion create. The following example creates an Azure Bastion host named bastion in the AzureBastionSubnet subnet of the vnet-1 virtual network. Azure Bastion is used to securely connect Azure virtual machines without exposing them to the public internet.
az network bastion create \
--resource-group test-rg \
--name bastion \
--vnet-name vnet-1 \
--public-ip-address public-ip-bastion \
--location eastus2 \
--no-wait
Create a second virtual network
Create a second virtual network with az network vnet create. The following example creates a virtual network named vnet-2 with the address prefix 10.1.0.0/16.
Note
The second virtual network can be in the same region as the first virtual network or in a different region. You don't need a Bastion deployment for the second virtual network. After the network peer, you can connect to both virtual machines with the same Bastion deployment.
az network vnet create \
--name vnet-2 \
--resource-group test-rg \
--address-prefixes 10.1.0.0/16 \
--subnet-name subnet-1 \
--subnet-prefix 10.1.0.0/24