Skip to content

Commit fa2ee54

Browse files
committed
Update cross tenant
1 parent f737fe9 commit fa2ee54

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

articles/vpn-gateway/vpn-gateway-vnet-vnet-rm-ps.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ author: cherylmc
66
ms.service: azure-vpn-gateway
77
ms.custom: devx-track-azurepowershell
88
ms.topic: how-to
9-
ms.date: 09/24/2024
9+
ms.date: 03/25/2025
1010
ms.author: cherylmc
1111
---
1212
# Configure a VNet-to-VNet VPN gateway connection using PowerShell
1313

14-
This article helps you connect virtual networks by using the VNet-to-VNet connection type. The virtual networks can be in the same or different regions, and from the same or different subscriptions. When you connect virtual networks from different subscriptions, the subscriptions don't need to be associated with the same tenant. If you already have VNets that you want to connect and they're in the same subscription, you might want to use the [Azure portal](vpn-gateway-howto-vnet-vnet-resource-manager-portal.md) steps instead because the process is less complicated. Note that you can't connect VNets from different subscriptions using the Azure portal.
14+
This article helps you connect virtual networks by using the VNet-to-VNet connection type. The virtual networks can be in the same or different regions, and from the same or different subscriptions. When you connect virtual networks from different subscriptions, the subscriptions don't need to be associated with the same tenant. If you already have VNets that you want to connect and they're in the same subscription, you might want to use the [Azure portal](vpn-gateway-howto-vnet-vnet-resource-manager-portal.md) steps instead because the process is less complicated. Note that you can't connect VNets from different subscriptions using the Azure portal.
1515

1616
In this exercise, you create the required virtual networks (VNets) and VPN gateways. We have steps to connect VNets within the same subscription, as well as steps and commands for the more complicated scenario to connect VNets in different subscriptions. The PowerShell cmdlet to create a connection is [New-AzVirtualNetworkGatewayConnection](/powershell/module/az.network/new-azvirtualnetworkgatewayconnection). The `-ConnectionType` is `Vnet2Vnet`.
1717

@@ -23,7 +23,7 @@ There are multiple ways to connect VNets. The following sections describe differ
2323

2424
### VNet-to-VNet
2525

26-
Configuring a VNet-to-VNet connection is a good way to easily connect VNets. Connecting a virtual network to another virtual network using the VNet-to-VNet connection type (VNet2VNet) is similar to creating a Site-to-Site IPsec connection to an on-premises location. Both connectivity types use a VPN gateway to provide a secure tunnel using IPsec/IKE, and both function the same way when communicating. The difference between the connection types is the way the local network gateway is configured. When you create a VNet-to-VNet connection, you don't see the local network gateway address space. It's automatically created and populated. If you update the address space for one VNet, the other VNet automatically knows to route to the updated address space. Creating a VNet-to-VNet connection is typically faster and easier than creating a Site-to-Site connection between VNets.
26+
Configuring a VNet-to-VNet connection is a good way to easily connect VNets. Connecting a virtual network to another virtual network using the VNet-to-VNet connection type (VNet2VNet) is similar to creating a Site-to-Site IPsec connection to an on-premises location. Both connectivity types use a VPN gateway to provide a secure tunnel using IPsec/IKE, and both function the same way when communicating. The difference between the connection types is the way the local network gateway is configured. When you create a VNet-to-VNet connection, you don't see the local network gateway address space. It's automatically created and populated. If you update the address space for one VNet, the other VNet automatically knows to route to the updated address space. Creating a VNet-to-VNet connection is typically faster and easier than creating a Site-to-Site connection between VNets.
2727

2828
### Site-to-Site (IPsec)
2929

@@ -56,7 +56,7 @@ For this exercise, you can combine configurations, or just choose the one that y
5656

5757
* [VNets that reside in the same subscription](#samesub): The steps for this configuration use TestVNet1 and TestVNet4.
5858

59-
* [VNets that reside in different subscriptions](#difsub): The steps for this configuration use TestVNet1 and TestVNet5.
59+
* [VNets that reside in different subscriptions](#difsub): The steps for this configuration use TestVNet1 and TestVNet5. If the virtual networks aren't in the same tenant, there are [additional instructions](#tenant) that you must follow. Read those instructions first to understand where they fall within the steps of the exercise.
6060

6161
## <a name="samesub"></a>How to connect VNets that are in the same subscription
6262

@@ -447,6 +447,36 @@ In this example, because the gateways are in the different subscriptions, we've
447447
New-AzVirtualNetworkGatewayConnection -Name $Connection51 -ResourceGroupName $RG5 -VirtualNetworkGateway1 $vnet5gw -VirtualNetworkGateway2 $vnet1gw -Location $Location5 -ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'
448448
```
449449

450+
### <a name="tenant"></a>Different subscriptions and different tenants
451+
452+
This scenario makes use of the previous scenario steps, but with a few key differences. In this scenario, TestVNet5 resides in Subscription 1, Tenant 1. TestVNet1 resides in Subscription2, Tenant 2.
453+
454+
In this scenario, when you create the TestVNet1 gateway, you need to connect to Tenant2, Subscription2 using the following commands. Adjust or declare any variables as needed.
455+
456+
```azurepowershell-interactive
457+
Connect-AzAccount -TenantID $Tenant2
458+
Select-AzSubscription -SubscriptionId $subscription2
459+
<Other PS commandlets to create TestVNet1 gateway are same as above>
460+
$vnet1gw = Get-AzVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $RG1
461+
```
462+
463+
When you create and configure TestVNet5 gateway, you need to connect to Tenant1, Subscription1 using the following commands, adjusting any variables as needed.
464+
465+
```azurepowershell-interactive
466+
Connect-AzAccount -TenantID $Tenant2
467+
Select-AzSubscription -SubscriptionId $subscription2
468+
$vnet5gw = Get-AzVirtualNetworkGateway -Name $GWName5 -ResourceGroupName $RG1
469+
```
470+
471+
When you create create Vnet2Vnet VirtualNetworkGatewayConnection with VirtualNetworkGateway1 as $vnet1gw, you need to connect to Tenant2, Subscription2 first and other commands are same the previous section.
472+
473+
```azurepowershell-interactive
474+
Connect-AzAccount -TenantID $Tenant2
475+
Select-AzSubscription -SubscriptionId $subscription2
476+
$vnet1gw = Get-AzVirtualNetworkGateway -Name $GWName1 -ResourceGroupName $RG1
477+
New-AzVirtualNetworkGatewayConnection -Name $Connection51 -ResourceGroupName $RG5 -VirtualNetworkGateway1 $vnet5gw -VirtualNetworkGateway2 $vnet1gw -Location $Location5 -ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'
478+
```
479+
450480
## <a name="verify"></a>How to verify a connection
451481

452482
[!INCLUDE [vpn-gateway-no-nsg-include](../../includes/vpn-gateway-no-nsg-include.md)]

0 commit comments

Comments
 (0)