Skip to content

Commit 2b3e876

Browse files
authored
Merge pull request #191707 from asudbring/lb-nat-howto-portal
Added powershell instructions to article
2 parents 45d53a5 + 5356277 commit 2b3e876

File tree

3 files changed

+138
-15
lines changed

3 files changed

+138
-15
lines changed

articles/load-balancer/manage-inbound-nat-rules.md

Lines changed: 138 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: asudbring
55
ms.author: allensu
66
ms.service: load-balancer
77
ms.topic: how-to
8-
ms.date: 03/10/2022
8+
ms.date: 03/15/2022
99
ms.custom: template-how-to #Required; leave this attribute/value as-is.
1010
---
1111
# Manage inbound NAT rules for Azure Load Balancer using the Azure portal
@@ -22,17 +22,19 @@ In this article, you'll learn how to add and remove an inbound NAT rule for both
2222

2323
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
2424

25-
[!INCLUDE [azure-cli-prepare-your-environment.md](../../includes/azure-cli-prepare-your-environment.md)]
26-
27-
- This quickstart requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
25+
## Prerequisites
2826

2927
- A standard public load balancer in your subscription. For more information on creating an Azure Load Balancer, see [Quickstart: Create a public load balancer to load balance VMs using the Azure portal](quickstart-load-balancer-standard-public-portal.md). The load balancer name for the examples in this article is **myLoadBalancer**.
3028

29+
[!INCLUDE [azure-cli-prepare-your-environment.md](../../includes/azure-cli-prepare-your-environment-no-header.md)]
30+
31+
- If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run `Get-Module -ListAvailable Az` to find the installed version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-Az-ps). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure.
32+
3133
## Add a single VM inbound NAT rule
3234

3335
# [**Portal**](#tab/inbound-nat-rule-portal)
3436

35-
In this example, you'll create an inbound NAT rule to forward port 500 to backend port 443.
37+
In this example, you'll create an inbound NAT rule to forward port **500** to backend port **443**.
3638

3739
1. Sign in to the [Azure portal](https://portal.azure.com).
3840

@@ -64,9 +66,41 @@ In this example, you'll create an inbound NAT rule to forward port 500 to backen
6466

6567
:::image type="content" source="./media/manage-inbound-nat-rules/add-single-instance-rule.png" alt-text="Screenshot of the create inbound NAT rule page":::
6668

69+
# [**PowerShell**](#tab/inbound-nat-rule-powershell)
70+
71+
In this example, you'll create an inbound NAT rule to forward port **500** to backend port **443**.
72+
73+
Use [Get-AzLoadBalancer](/powershell/module/az.network/get-azloadbalancer) to place the load balancer information into a variable.
74+
75+
Use [Add-AzLoadBalancerInboundNatRuleConfig](/powershell/module/az.network/add-azloadbalancerinboundnatruleconfig) to create the inbound NAT rule.
76+
77+
To save the configuration to the load balancer, use [Set-AzLoadBalancer](/powershell/module/az.network/set-azloadbalancer).
78+
79+
```azurepowershell
80+
## Place the load balancer information into a variable for later use. ##
81+
$slb = @{
82+
ResourceGroupName = 'myResourceGroup'
83+
Name = 'myLoadBalancer'
84+
}
85+
$lb = Get-AzLoadBalancer @slb
86+
87+
## Create the single virtual machine inbound NAT rule. ##
88+
$rule = @{
89+
Name = 'myInboundNATrule'
90+
Protocol = 'Tcp'
91+
FrontendIpConfiguration = $lb.FrontendIpConfigurations[0]
92+
FrontendPort = '500'
93+
BackendPort = '443'
94+
}
95+
$lb | Add-AzLoadBalancerInboundNatRuleConfig @rule
96+
97+
$lb | Set-AzLoadBalancer
98+
99+
```
100+
67101
# [**CLI**](#tab/inbound-nat-rule-cli)
68102

69-
In this example, you'll create an inbound NAT rule to forward port 500 to backend port 443.
103+
In this example, you'll create an inbound NAT rule to forward port **500** to backend port **443**.
70104

71105
Use [az network lb inbound-nat-rule create](/cli/azure/network/lb/inbound-nat-rule#az-network-lb-inbound-nat-rule-create) to create the NAT rule.
72106

@@ -87,7 +121,7 @@ Use [az network lb inbound-nat-rule create](/cli/azure/network/lb/inbound-nat-ru
87121

88122
# [**Portal**](#tab/inbound-nat-rule-portal)
89123

90-
In this example, you'll create an inbound NAT rule to forward a range of ports starting at port 500 to backend port 443.
124+
In this example, you'll create an inbound NAT rule to forward a range of ports starting at port 500 to backend port 443. The maximum number of machines in the backend pool is set by the parameter **Maximum number of machines in backend pool** with a value of **500**. This setting will limit the backend pool to **500** virtual machines.
91125

92126
1. Sign in to the [Azure portal](https://portal.azure.com).
93127

@@ -110,17 +144,51 @@ In this example, you'll create an inbound NAT rule to forward a range of ports s
110144
| Target backend pool | Select your backend pool. In this example, it's **myBackendPool**. |
111145
| Frontend IP address | Select your frontend IP address. In this example, it's **myFrontend**. |
112146
| Frontend port range start | Enter **500**. |
113-
| Maximum number of machines in backend pool | Enter **1000**. |
147+
| Maximum number of machines in backend pool | Enter **500**. |
114148
| Backend port | Enter **443**. |
115149
| Protocol | Select **TCP**. |
116150

117151
7. Leave the rest at the defaults and select **Add**.
118152

119153
:::image type="content" source="./media/manage-inbound-nat-rules/add-inbound-nat-rule.png" alt-text="Screenshot of the add inbound NAT rules page":::
120154

155+
# [**PowerShell**](#tab/inbound-nat-rule-powershell)
156+
157+
In this example, you'll create an inbound NAT rule to forward a range of ports starting at port 500 to backend port 443. The maximum number of machines in the backend pool is set by the parameter `-FrontendPortRangeEnd` with a value of **1000**. This setting will limit the backend pool to **500** virtual machines.
158+
159+
Use [Get-AzLoadBalancer](/powershell/module/az.network/get-azloadbalancer) to place the load balancer information into a variable.
160+
161+
Use [Add-AzLoadBalancerInboundNatRuleConfig](/powershell/module/az.network/add-azloadbalancerinboundnatruleconfig) to create the inbound NAT rule.
162+
163+
To save the configuration to the load balancer, use [Set-AzLoadBalancer](/powershell/module/az.network/set-azloadbalancer)
164+
165+
```azurepowershell
166+
## Place the load balancer information into a variable for later use. ##
167+
$slb = @{
168+
ResourceGroupName = 'myResourceGroup'
169+
Name = 'myLoadBalancer'
170+
}
171+
$lb = Get-AzLoadBalancer @slb
172+
173+
## Create the multiple virtual machines inbound NAT rule. ##
174+
$rule = @{
175+
Name = 'myInboundNATrule'
176+
Protocol = 'Tcp'
177+
BackendPort = '443'
178+
FrontendIpConfiguration = $lb.FrontendIpConfigurations[0]
179+
FrontendPortRangeStart = '500'
180+
FrontendPortRangeEnd = '1000'
181+
BackendAddressPool = $lb.BackendAddressPools[0]
182+
}
183+
$lb | Add-AzLoadBalancerInboundNatRuleConfig @rule
184+
185+
$lb | Set-AzLoadBalancer
186+
187+
```
188+
121189
# [**CLI**](#tab/inbound-nat-rule-cli)
122190

123-
In this example, you'll create an inbound NAT rule to forward a range of ports starting at port 500 to backend port 443.
191+
In this example, you'll create an inbound NAT rule to forward a range of ports starting at port 500 to backend port 443. The maximum number of machines in the backend pool is set by the parameter `--frontend-port-range-end` with a value of **1000**. This setting will limit the backend pool to **500** virtual machines.
124192

125193
Use [az network lb inbound-nat-rule create](/cli/azure/network/lb/inbound-nat-rule#az-network-lb-inbound-nat-rule-create) to create the NAT rule.
126194

@@ -144,7 +212,7 @@ Use [az network lb inbound-nat-rule create](/cli/azure/network/lb/inbound-nat-ru
144212

145213
# [**Portal**](#tab/inbound-nat-rule-portal)
146214

147-
To accommodate more virtual machines in the backend pool in a multiple instance rule, change the frontend port allocation in the inbound NAT rule. In this example, you'll change the frontend port allocation from 500 to 1000.
215+
To accommodate more virtual machines in the backend pool in a multiple instance rule, change the frontend port allocation in the inbound NAT rule. In this example, you'll change the **Maximum number of machines in backend pool** from **500** to **1000**. This setting will increase the maximum number of machines in the backend pool to **1000**.
148216

149217
1. Sign in to the [Azure portal](https://portal.azure.com).
150218

@@ -158,21 +226,51 @@ To accommodate more virtual machines in the backend pool in a multiple instance
158226

159227
:::image type="content" source="./media/manage-inbound-nat-rules/select-inbound-nat-rule.png" alt-text="Screenshot of inbound NAT rule overview.":::
160228

161-
6. In the properties of the inbound NAT rule, change the value in **Frontend port range start** to **1000**.
229+
6. In the properties of the inbound NAT rule, change the value in **Maximum number of machines in backend pool** to **1000**.
162230

163231
7. Select **Save**.
164232

165233
:::image type="content" source="./media/manage-inbound-nat-rules/change-frontend-ports.png" alt-text="Screenshot of inbound NAT rule properties page.":::
166234

235+
# [**PowerShell**](#tab/inbound-nat-rule-powershell)
236+
237+
To accommodate more virtual machines in the backend pool in a multiple instance rule, change the frontend port allocation in the inbound NAT rule. In this example, you'll change the parameter `-FrontendPortRangeEnd` to **1500**. This setting will increase the maximum number of machines in the backend pool to **1000**.
238+
239+
Use [Get-AzLoadBalancer](/powershell/module/az.network/get-azloadbalancer) to place the load balancer information into a variable.
240+
241+
To change the port allocation, use [Set-AzLoadBalancerInboundNatRuleConfig](/powershell/module/az.network/set-azloadbalancerinboundnatruleconfig).
242+
243+
```azurepowershell
244+
## Place the load balancer information into a variable for later use. ##
245+
$slb = @{
246+
ResourceGroupName = 'myResourceGroup'
247+
Name = 'myLoadBalancer'
248+
}
249+
$lb = Get-AzLoadBalancer @slb
250+
251+
## Set the new port allocation
252+
$rule = @{
253+
Name = 'myInboundNATrule'
254+
Protocol = 'Tcp'
255+
BackendPort = '443'
256+
FrontendIpConfiguration = $lb.FrontendIpConfigurations[0]
257+
FrontendPortRangeStart = '500'
258+
FrontendPortRangeEnd = '1500'
259+
BackendAddressPool = $lb.BackendAddressPools[0]
260+
}
261+
$lb | Set-AzLoadBalancerInboundNatRuleConfig @rule
262+
263+
```
264+
167265
# [**CLI**](#tab/inbound-nat-rule-cli)
168266

169-
To accommodate more virtual machines in the backend pool, change the frontend port allocation in the inbound NAT rule. In this example, you'll change the frontend port allocation from 500 to 1000.
267+
To accommodate more virtual machines in the backend pool, change the frontend port allocation in the inbound NAT rule. In this example, you'll change the parameter `--frontend-port-range-end` to **1500**. This setting will increase the maximum number of machines in the backend pool to **1000**
170268

171269
Use [az network lb inbound-nat-rule update](/cli/azure/network/lb/inbound-nat-rule#az-network-lb-inbound-nat-rule-update) to change the frontend port allocation.
172270

173271
```azurecli
174272
az network lb inbound-nat-rule update \
175-
--frontend-port-range-start 1000 \
273+
--frontend-port-range-end 1500 \
176274
--lb-name myLoadBalancer \
177275
--name myInboundNATrule \
178276
--resource-group myResourceGroup
@@ -183,7 +281,7 @@ Use [az network lb inbound-nat-rule update](/cli/azure/network/lb/inbound-nat-ru
183281

184282
## View port mappings
185283

186-
Port mappings for the virtual machines in the backend pool can be viewed by using the Azure portal. In this example, you'll use the Azure portal to view the port mappings:
284+
Port mappings for the virtual machines in the backend pool can be viewed by using the Azure portal.
187285

188286
1. Sign in to the [Azure portal](https://portal.azure.com).
189287

@@ -221,11 +319,36 @@ In this example, you'll remove an inbound NAT rule.
221319

222320
:::image type="content" source="./media/manage-inbound-nat-rules/remove-inbound-nat-rule.png" alt-text="Screenshot of inbound NAT rule removal.":::
223321

322+
# [**PowerShell**](#tab/inbound-nat-rule-powershell)
323+
324+
In this example, you'll remove an inbound NAT rule.
325+
326+
Use [Get-AzLoadBalancer](/powershell/module/az.network/get-azloadbalancer) to place the load balancer information into a variable.
327+
328+
To remove the inbound NAT rule, use [Remove-AzLoadBalancerInboundNatRuleConfig](/powershell/module/az.network/remove-azloadbalancerinboundnatruleconfig).
329+
330+
To save the configuration to the load balancer, use [Set-AzLoadBalancer](/powershell/module/az.network/set-azloadbalancer).
331+
332+
```azurepowershell
333+
## Place the load balancer information into a variable for later use. ##
334+
$slb = @{
335+
ResourceGroupName = 'myResourceGroup'
336+
Name = 'myLoadBalancer'
337+
}
338+
$lb = Get-AzLoadBalancer @slb
339+
340+
## Remove the inbound NAT rule
341+
$lb | Remove-AzLoadBalancerInboundNatRuleConfig -Name 'myInboundNATrule'
342+
343+
$lb | Set-AzLoadBalancer
344+
345+
```
346+
224347
# [**CLI**](#tab/inbound-nat-rule-cli)
225348

226349
In this example, you'll remove an inbound NAT rule.
227350

228-
Use [az network lb inbound-nat-rule delete](/cli/azure/network/lb/inbound-nat-rule#az-network-lb-inbound-nat-rule-delete) to remove the NAT rule.
351+
Use [az network lb inbound-nat-rule delete](/cli/azure/network/lb/inbound-nat-rule#az-network-lb-inbound-nat-rule-delete) to remove the rule.
229352

230353
```azurecli
231354
az network lb inbound-nat-rule delete \
10.3 KB
Loading
-150 KB
Loading

0 commit comments

Comments
 (0)