Skip to content

Commit 9992fac

Browse files
authored
Merge pull request #185624 from reasuquo/newdoc
newarticle
2 parents 004eae8 + d1df6c5 commit 9992fac

File tree

3 files changed

+180
-11
lines changed

3 files changed

+180
-11
lines changed

articles/virtual-wan/TOC.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@
128128
- name: Configure custom IPsec policy
129129
href: virtual-wan-custom-ipsec-portal.md
130130
- name: Configure NAT rules
131-
href: nat-rules-vpn-gateway.md
131+
items:
132+
- name: Azure portal
133+
href: nat-rules-vpn-gateway.md
134+
- name: Azure PowerShell
135+
href: nat-rules-vpn-gateway-powershell.md
132136
- name: User VPN (point-to-site)
133137
items:
134138
- name: Create User VPN
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: 'Configure VPN NAT rules for your gateway using PowerShell'
3+
titleSuffix: Azure Virtual WAN
4+
description: Learn how to configure NAT rules for your VWAN VPN gateway using PowerShell.
5+
services: virtual-wan
6+
author: reasuquo
7+
ms.service: virtual-wan
8+
ms.topic: how-to
9+
ms.date: 01/20/2022
10+
ms.author: reasuquo
11+
12+
---
13+
14+
# Configure NAT Rules for your Virtual WAN VPN gateway using PowerShell
15+
16+
You can configure your Virtual WAN VPN gateway with static one-to-one NAT rules. A NAT rule provides a mechanism to set up one-to-one translation of IP addresses. NAT can be used to interconnect two IP networks that have incompatible or overlapping IP addresses. A typical scenario is branches with overlapping IPs that want to access Azure VNet resources.
17+
18+
This configuration uses a flow table to route traffic from an external (host) IP Address to an internal IP address associated with an endpoint inside a virtual network (virtual machine, computer, container, etc.). In order to use NAT, VPN devices need to use any-to-any (wildcard) traffic selectors. Policy Based (narrow) traffic selectors are not supported in conjunction with NAT configuration.
19+
20+
## Prerequisites
21+
22+
* Verify that you have an Azure subscription. If you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits](https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details) or sign up for a [free account](https://azure.microsoft.com/pricing/free-trial).
23+
* This tutorial will create a NAT rule on a VpnGateway which will be associated with a VpnSiteConnection, so this assumes you have an existing VpnGateway connection to two branches with overlapping address spaces.
24+
25+
### Azure PowerShell
26+
27+
[!INCLUDE [PowerShell](../../includes/vpn-gateway-cloud-shell-powershell-about.md)]
28+
29+
## <a name="signin"></a>Sign in
30+
31+
[!INCLUDE [sign in](../../includes/vpn-gateway-cloud-shell-ps-login.md)]
32+
33+
## <a name="rules"></a>Configure NAT rules
34+
35+
You can configure and view NAT rules on your VPN gateway settings at any time using Azure PowerShell
36+
37+
:::image type="content" source="./media/nat-rules-vpn-gateway/edit-rules.png" alt-text="Screenshot showing how to edit rules."lightbox="./media/nat-rules-vpn-gateway/edit-rules.png":::
38+
39+
1. Declare the variables for the existing resources
40+
41+
```azurepowershell-interactive
42+
$resourceGroup = Get-AzResourceGroup -ResourceGroupName "testRG"
43+
$virtualWan = Get-AzVirtualWan -ResourceGroupName "testRG" -Name "myVirtualWAN"
44+
$virtualHub = Get-AzVirtualHub -ResourceGroupName "testRG" -Name "westushub"
45+
$vpnGateway = Get-AzVpnGateway -ResourceGroupName "testRG" -Name "testvpngw"
46+
```
47+
48+
1. Create the new NAT rule to ensure the Site-to-site VPN gateway is able to distinguish between the two branches with overlapping address spaces.
49+
50+
You can set the parameters for the following values:
51+
52+
* **Name:** A unique name for your NAT rule.
53+
* **Type:** Static or Dynamic. Static one-to-one NAT establishes a one-to-one relationship between an internal address and an external address. The subnet size for both internal and external mapping must be the same for static.
54+
* **Mode:** IngressSnat or EgressSnat.
55+
* IngressSnat mode (also known as Ingress Source NAT) is applicable to traffic entering the Azure hub’s Site-to-site VPN gateway.
56+
* EgressSnat mode (also known as Egress Source NAT) is applicable to traffic leaving the Azure hub’s Site-to-site VPN gateway.
57+
* **InternalMapping:** An address prefix range of source IPs on the inside network that will be mapped to a set of external IPs. In other words, your pre-NAT address prefix range.
58+
* **ExternalMapping:** An address prefix range of destination IPs on the outside network that source IPs will be mapped to. In other words, your post-NAT address prefix range.
59+
* **Link Connection:** Connection resource that virtually connects a VPN site to the Azure Virtual WAN Hub's Site-to-site VPN gateway.
60+
61+
### Syntax
62+
63+
```
64+
New-AzVpnGatewayNatRule
65+
-ResourceGroupName <String>
66+
-ParentResourceName <String>
67+
-Name <String>
68+
[-Type <String>]
69+
[-Mode <String>]
70+
-InternalMapping <String[]>
71+
-ExternalMapping <String[]>
72+
[-InternalPortRange <String[]>]
73+
[-ExternalPortRange <String[]>]
74+
[-IpConfigurationId <String>]
75+
[-AsJob]
76+
[-DefaultProfile <IAzureContextContainer>]
77+
[-WhatIf]
78+
[-Confirm] [<CommonParameters>]
79+
```
80+
81+
```azurepowershell-interactive
82+
$natrule = New-AzVpnGatewayNatRule -ResourceGroupName "testRG" -ParentResourceName "testvpngw" -Name "testNatRule" -InternalMapping "10.0.0.0/24" -ExternalMapping "1.2.3.4/32" -IpConfigurationId "Instance0" -Type Dynamic -Mode EgressSnat
83+
```
84+
85+
1. Declare the variable to create a new object for the new NAT rule
86+
87+
```azurepowershell-interactive
88+
$newruleobject = New-Object Microsoft.Azure.Commands.Network.Models.PSResourceId
89+
$newruleobject.Id = $natrule.Id
90+
```
91+
92+
1. Declare the variable to get the existing VPN connection
93+
94+
```azurepowershell-interactive
95+
$conn = Get-AzVpnConnection -Name "Connection-VPNsite1" -ResourceGroupName "testRG" -ParentResourceName "testvpngw"
96+
```
97+
98+
1. Set the appropriate index for the NAT rule in the VPN connection
99+
100+
```azurepowershell-interactive
101+
$conn.VpnLinkConnections
102+
$conn.VpnLinkConnections[0].EgressNatRules = $newruleobject
103+
```
104+
105+
1. Finally, update the existing VPN connection with the new NAT rule
106+
107+
```azurepowershell-interactive
108+
Update-AzVpnConnection -Name "Connection-VPNsite1" -ResourceGroupName "testRG" -ParentResourceName "testvpngw" -VpnSiteLinkConnection $conn.VpnLinkConnections
109+
```
110+
111+
## Next steps
112+
113+
For more information about Site-to-site configurations, see [Configure a Virtual WAN Site-to-site connection](virtual-wan-site-to-site-portal.md).

articles/virtual-wan/site-to-site-powershell.md

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.author: reasuquo
1212
ms.custom: devx-track-azurepowershell
1313

1414
---
15-
# Create a site-to-site connection to Azure Virtual WAN using PowerShell
15+
# Create a Site-to-Site connection to Azure Virtual WAN using PowerShell
1616

1717
This article shows you how to use Virtual WAN to connect to your resources in Azure over an IPsec/IKE (IKEv1 and IKEv2) VPN connection via PowerShell. This type of connection requires a VPN device located on-premises that has an externally facing public IP address assigned to it. For more information about Virtual WAN, see the [Virtual WAN Overview](virtual-wan-about.md).
1818

@@ -37,31 +37,31 @@ This article shows you how to use Virtual WAN to connect to your resources in Az
3737

3838
## <a name="openvwan"></a>Create a virtual WAN
3939

40-
Before you can create a virtual WAN, you have to create a resource group to host the virtual WAN or use an existing resource group. Create a resource group with [New-AzResourceGroup](/powershell/module/az.Resources/New-azResourceGroup). This example creates a new resource group named **testRG** in the **West US** location:
40+
Before you can create a virtual wan, you have to create a resource group to host the virtual wan or use an existing resource group. Create a resource group with [New-AzResourceGroup](/powershell/module/az.Resources/New-azResourceGroup). This example creates a new resource group named **testRG** in the **West US** location:
4141

4242
Create a resource group:
4343

4444
```azurepowershell-interactive
4545
New-AzResourceGroup -Location "West US" -Name "testRG"
4646
```
4747

48-
Create the virtual WAN:
48+
Create the virtual wan:
4949

5050
```azurepowershell-interactive
5151
$virtualWan = New-AzVirtualWan -ResourceGroupName testRG -Name myVirtualWAN -Location "West US"
5252
```
5353

54-
### To create the virtual WAN in an already existing resource group
54+
### To create the virtual wan in an already existing resource group
5555

56-
Use the steps in this section if you need to create the virtual WAN in an already existing resource group.
56+
Use the steps in this section if you need to create the virtual wan in an already existing resource group.
5757

58-
1. Set the variables for the existing resource group.
58+
1. Set the variables for the existing resource group
5959

6060
```azurepowershell-interactive
6161
$resourceGroup = Get-AzResourceGroup -ResourceGroupName "testRG"
6262
```
6363

64-
2. Create the virtual WAN.
64+
2. Create the virtual wan.
6565

6666
```azurepowershell-interactive
6767
$virtualWan = New-AzVirtualWan -ResourceGroupName testRG -Name myVirtualWAN -Location "West US"
@@ -83,7 +83,7 @@ In this section, you create a site-to-site VPN gateway that will be in the same
8383
New-AzVpnGateway -ResourceGroupName "testRG" -Name "testvpngw" -VirtualHubId $virtualHub.Id -VpnGatewayScaleUnit 2
8484
```
8585

86-
Once your VPN gateway is created, you can view it using the following example.
86+
Once your VPNgateway is created, you can view it using the following example.
8787

8888
```azurepowershell-interactive
8989
Get-AzVpnGateway -ResourceGroupName "testRG" -Name "testvpngw"
@@ -93,7 +93,7 @@ Get-AzVpnGateway -ResourceGroupName "testRG" -Name "testvpngw"
9393

9494
In this section, you create sites that correspond to your physical locations and the connections. These sites contain your on-premises VPN device endpoints, you can create up to 1000 sites per virtual hub in a virtual WAN. If you have multiple hubs, you can create 1000 per each of those hubs.
9595

96-
Set the variable for the VPN gateway and for the IP address space that is located on your on-premises site, traffic destined for this address space is routed to your local site. This is required when BGP is not enabled for the site:
96+
Set the variable for the vpnGateway and for the IP address space that is located on your on-premises site, traffic destined for this address space is routed to your local site. This is required when BGP is not enabled for the site:
9797

9898
```azurepowershell-interactive
9999
$vpnGateway = Get-AzVpnGateway -ResourceGroupName "testRG" -Name "testvpngw"
@@ -116,7 +116,7 @@ Create the vpnSite and reference the variables of the vpnSiteLinks just created:
116116
$vpnSite = New-AzVpnSite -ResourceGroupName "testRG" -Name "testVpnSite" -Location "West US" -VirtualWan $virtualWan -AddressSpace $vpnSiteAddressSpaces -DeviceModel "SomeDevice" -DeviceVendor "SomeDeviceVendor" -VpnSiteLink @($vpnSiteLink1, $vpnSiteLink2)
117117
```
118118

119-
Next is the VPN Site Link connection which is composed of 2 Active-Active tunnels from a branch/Site known as VPNSite to the scalable gateway:
119+
Next is the Vpn Site Link connection which is composed of 2 Active-Active tunnels from a branch/Site known as VPNSite to the scalable gateway:
120120

121121
```azurepowershell-interactive
122122
$vpnSiteLinkConnection1 = New-AzVpnSiteLinkConnection -Name "testLinkConnection1" -VpnSiteLink $vpnSite.VpnSiteLinks[0] -ConnectionBandwidth 100
@@ -135,6 +135,58 @@ New-AzVpnConnection -ResourceGroupName $vpnGateway.ResourceGroupName -ParentReso
135135

136136
When you no longer need the resources that you created, delete them. Some of the Virtual WAN resources must be deleted in a certain order due to dependencies. Deleting can take about 30 minutes to complete.
137137

138+
1. Declare the variables
139+
140+
```azurepowershell-interactive
141+
$resourceGroup = Get-AzResourceGroup -ResourceGroupName "testRG"
142+
$virtualWan = Get-AzVirtualWan -ResourceGroupName "testRG" -Name "myVirtualWAN"
143+
$virtualHub = Get-AzVirtualHub -ResourceGroupName "testRG" -Name "westushub"
144+
$vpnGateway = Get-AzVpnGateway -ResourceGroupName "testRG" -Name "testvpngw"
145+
```
146+
147+
1. Delete all gateway entities following the below order for the VPN gateway. This can take 30 minutes to complete.
148+
149+
Delete the VPN Gateway connection to the VPN Sites.
150+
151+
```azurepowershell-interactive
152+
Remove-AzVpnConnection -ResourceGroupName $vpnGateway.ResourceGroupName -ParentResourceName $vpnGateway.Name -Name "testConnection"
153+
```
154+
155+
Delete the VPN Gateway.
156+
Note that deleting a VPN Gateway will also remove all VPN Express Route Connections associated with it.
157+
158+
```azurepowershell-interactive
159+
Remove-AzVpnGateway -ResourceGroupName "testRG" -Name "testvpngw"
160+
```
161+
162+
1. You can delete the Resource Group to delete all the other resources in the resource group, including the hubs, sites and the virtual WAN.
163+
164+
```azurepowershell-interactive
165+
Remove-AzResourceGroup -Name "testRG"
166+
```
167+
168+
1. Or you can choose to delete each of the resources in the Resource Group
169+
170+
Delete the VPN site
171+
172+
```azurepowershell-interactive
173+
Remove-AzVpnSite -ResourceGroupName "testRG" -Name "testVpnSite"
174+
```
175+
176+
Delete the Virtual Hub
177+
178+
```azurepowershell-interactive
179+
Remove-AzVirtualHub -ResourceGroupName "testRG" -Name "westushub"
180+
```
181+
182+
Delete the Virtual WAN
183+
184+
```azurepowershell-interactive
185+
Remove-AzVirtualWan -Name "MyVirtualWan" -ResourceGroupName "testRG"
186+
```
187+
188+
189+
138190
## Next steps
139191
140192
Next, to learn more about Virtual WAN, see:

0 commit comments

Comments
 (0)