Skip to content

Commit a767d33

Browse files
committed
Creation of article on outbound rules using Azure PowerShell
1 parent b66a352 commit a767d33

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
title: Configure load balancing and outbound rules using Azure PowerShell
3+
titlesuffix: Azure Load Balancer
4+
description: This article shows how to configure load balancing and outbound rules in a Standard Load Balancer using the Azure PowerShell.
5+
services: load-balancer
6+
author: asudbring
7+
ms.service: load-balancer
8+
ms.topic: article
9+
ms.date: 04/01/2019
10+
ms.author: allensu
11+
12+
---
13+
# Configure load balancing and outbound rules in Standard Load Balancer using Azure PowerShell
14+
15+
This article shows you how to configure outbound rules in Standard Load Balancer using Azure PowerShell.
16+
17+
When you are done, the Load Balancer resource contains two frontends and rules associated with them: one for inbound and another for outbound. Each frontend has a reference to a public IP address and this scenario uses a different public IP address for inbound versus outbound. The load balancing rule provides only inbound load balancing and the outbound rule controls the outbound NAT provided for the VM. This article uses two separate backend pools, one for inbound and one for outbound, to illustrate capability and allow for flexibility for this scenario.
18+
19+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
20+
21+
[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)]
22+
23+
## Connect to Azure Account
24+
Sign in to your Azure subscription with the [Connect-AzAccount](https://docs.microsoft.com/powershell/module/az.accounts/connect-azaccount?view=azps-2.5.0) command and follow the on-screen directions:
25+
26+
```azurepowershell-interactive
27+
Connect-AzAccount
28+
```
29+
## Create resource group
30+
31+
Create a resource group with [New-AzResourceGroup](https://docs.microsoft.com/powershell/module/az.resources/new-azresourcegroup?view=azps-2.6.0). An Azure resource group is a logical container into which Azure resources are deployed and managed.
32+
33+
The following example creates a resource group named *myresourcegroupoutbound* in the *eastus2* location:
34+
35+
```azurepowershell-interactive
36+
New-AzResourceGroup -Name myresourcegroupoutbound -Location eastus
37+
```
38+
## Create virtual network
39+
Create a virtual network named *myvnetoutbound* with a subnet named *mysubnetoutbound* in the *myresourcegroupoutbound* using [New-AzVirtualNetwork](https://docs.microsoft.com/powershell/module/az.network/new-azvirtualnetwork?view=azps-2.6.0) and [New-AzVirtualNetworkSubnetConfig](https://docs.microsoft.com/powershell/module/az.network/new-azvirtualnetworksubnetconfig?view=azps-2.6.0):
40+
41+
```azurepowershell-interactive
42+
$subnet = New-AzVirtualNetworkSubnetConfig -Name mysubnetoutbound -AddressPrefix "192.168.0.0/24"
43+
44+
New-AzVirtualNetwork -Name myvnetoutbound -ResourceGroupName myresourcegroupoutbound -Location eastus -AddressPrefix "192.168.0.0/16" -Subnet $subnet
45+
```
46+
47+
## Create inbound Public IP address
48+
49+
To access your web app on the Internet, you need a public IP address for the load balancer. A Standard Load Balancer only supports Standard Public IP addresses. Use [New-AzPublicIpAddress](https://docs.microsoft.com/powershell/module/az.network/new-azpublicipaddress?view=azps-2.6.0) to create a Standard Public IP address named *mypublicipinbound* in *myresourcegroupoutbound*.
50+
51+
```azurepowershell-interactive
52+
$pubIPin = New-AzPublicIpAddress -ResourceGroupName myresourcegroupoutbound -Name mypublicipinbound -AllocationMethod Static -Sku Standard -Location eastus
53+
```
54+
55+
## Create outbound public IP address
56+
57+
Create a Standard IP address for Load Balancer's frontend outbound configuration using [New-AzPublicIpAddress](https://docs.microsoft.com/powershell/module/az.network/new-azpublicipaddress?view=azps-2.6.0).
58+
59+
```azurepowershell-interactive
60+
$pubIPout = New-AzPublicIpAddress -ResourceGroupName myresourcegroupoutbound -Name mypublicipoutbound -AllocationMethod Static -Sku Standard -Location eastus
61+
```
62+
63+
## Create Azure Load Balancer
64+
65+
This section details how you can create and configure the following components of the load balancer:
66+
- A frontend IP that receives the incoming network traffic on the load balancer.
67+
- A backend pool where the frontend IP sends the load balanced network traffic.
68+
- A backend pool for outbound connectivity.
69+
- A health probe that determines health of the backend VM instances.
70+
- A load balancer inbound rule that defines how traffic is distributed to the VMs.
71+
- A load balancer outbound rule that defines how traffic is distributed from the VMs.
72+
73+
### Create inbound frontend IP
74+
Create the outbound frontend IP configuration for the Load Balancer with [New-AzLoadBalancerFrontendIpConfig](https://docs.microsoft.com/powershell/module/az.network/new-azloadbalancerfrontendipconfig?view=azps-2.6.0) that includes an inbound frontend IP configuration named *myfrontendinbound* that is associated to the public IP address *mypublicipinbound*
75+
76+
```azurepowershell-interactive
77+
$frontendIPin = New-AzLoadBalancerFrontendIPConfig -Name "myfrontendinbound" -PublicIpAddress $pubIPin
78+
```
79+
### Create outbound frontend IP
80+
Create the outbound frontend IP configuration for the Load Balancer with [New-AzLoadBalancerFrontendIpConfig](https://docs.microsoft.com/powershell/module/az.network/new-azloadbalancerfrontendipconfig?view=azps-2.6.0) that includes an outbound frontend IP configuration named *myfrontendoutbound* that is associated to the public IP address *mypublicipoutbound*:
81+
82+
```azurepowershell-interactive
83+
$frontendIPout = New-AzLoadBalancerFrontendIPConfig -Name "myfrontendoutbound" -PublicIpAddress $pubIPout
84+
```
85+
### Create inbound backend pool
86+
Create the backend inbound pool for the load balancer with [New-AzLoadBalancerBackendAddressPoolConfig](https://docs.microsoft.com/powershell/module/az.network/new-azloadbalancerbackendaddresspoolconfig?view=azps-2.6.0) named *bepoolinbound*:
87+
88+
```azurepowershell-interactive
89+
$bepoolin = New-AzLoadBalancerBackendAddressPoolConfig -Name bepoolinbound
90+
```
91+
92+
### Create outbound backend pool
93+
Create an additional backend address pool to define outbound connectivity for a pool of VMs with [New-AzLoadBalancerBackendAddressPoolConfig](https://docs.microsoft.com/powershell/module/az.network/new-azloadbalancerbackendaddresspoolconfig?view=azps-2.6.0) named *bepooloutbound*.Creating a separate outbound pool provides maximum flexibility, but you can omit this step and only use the inbound *bepoolinbound* as well. :
94+
95+
```azurepowershell-interactive
96+
$bepoolout = New-AzLoadBalancerBackendAddressPoolConfig -Name bepooloutbound
97+
```
98+
99+
### Create health probe
100+
101+
A health probe checks all virtual machine instances to make sure they can send network traffic. The virtual machine instance with failed probe checks is removed from the load balancer until it goes back online and a probe check determines that it's healthy. Create a health probe with [New-AzLoadBalancerProbeConfig](https://docs.microsoft.com/powershell/module/az.network/new-azloadbalancerprobeconfig?view=azps-2.6.0) to monitor the health of the virtual machines.
102+
103+
```azurepowershell-interactive
104+
$probe = New-AzLoadBalancerProbeConfig -Name http -Protocol "http" -Port 80 -IntervalInSeconds 15 -ProbeCount 2 -RequestPath /
105+
```
106+
### Create load balancing rule
107+
108+
A load balancer rule defines the frontend IP configuration for the incoming traffic and the backend pool to receive the traffic, along with the required source and destination port. Create a load balancer rule *myinboundlbrule* with [New-AzLoadBalancerRuleConfig](https://docs.microsoft.com/powershell/module/az.network/new-azloadbalancerruleconfig?view=azps-2.6.0) for listening to port 80 in the frontend pool *myfrontendinbound* and sending load-balanced network traffic to the backend address pool *bepoolinbound* also using port 80.
109+
110+
>[!NOTE]
111+
>This load balancing rule disables automatic outbound (S)NAT as a result of this rule with the **-DisableOutboundSNAT parameter**. Outbound NAT is only provided by the outbound rule.
112+
113+
```azurecli-interactive
114+
az network lb rule create \
115+
--resource-group myresourcegroupoutbound \
116+
--lb-name lb \
117+
--name inboundlbrule \
118+
--protocol tcp \
119+
--frontend-port 80 \
120+
--backend-port 80 \
121+
--probe http \
122+
--frontend-ip-name myfrontendinbound \
123+
--backend-pool-name bepoolinbound \
124+
--disable-outbound-snat
125+
```
126+
### Create Load Balancer
127+
128+
Create a Load Balancer with the inbound IP address using [New-AzLoadBalancer](https://docs.microsoft.com/powershell/module/az.network/new-azloadbalancer?view=azps-2.6.0) named *lb* that includes an inbound frontend IP configuration and a backend pool *bepoolinbound* that is associated with the public IP address *mypublicipinbound* that you created in the preceding step.
129+
130+
```azurepowershell-interactive
131+
132+
```
133+
134+
135+
### Create outbound rule
136+
137+
An outbound rule defines the frontend public IP, represented by the frontend *myfrontendoutbound*, which will be used for all outbound NAT traffic as well as the backend pool to which this rule applies. Create an outbound rule *myoutboundrule* for outbound network translation of all virtual machines (NIC IP configurations) in *bepool* backend pool. The command below also changes the outbound idle timeout from 4 to 15 minutes and allocates 10000 SNAT ports instead of 1024. Review [outbound rules](https://aka.ms/lboutboundrules) for more details.
138+
139+
```azurecli-interactive
140+
az network lb outbound-rule create \
141+
--resource-group myresourcegroupoutbound \
142+
--lb-name lb \
143+
--name outboundrule \
144+
--frontend-ip-configs myfrontendoutbound \
145+
--protocol All \
146+
--idle-timeout 15 \
147+
--outbound-ports 10000 \
148+
--address-pool bepooloutbound
149+
```
150+
151+
If you do not want to use a separate outbound pool, you can change the address pool argument in the preceding command to specify *bepoolinbound* instead. We recommend to use separate pools for flexibility and readability of the resulting configuration.
152+
153+
At this point, you can proceed with adding your VM's to the backend pool *bepoolinbound* __and__ *bepooloutbound* by updating the IP configuration of the respective NIC resources using [az network nic ip-config address-pool add](https://docs.microsoft.com/cli/azure/network/lb/rule?view=azure-cli-latest).
154+
155+
## Clean up resources
156+
157+
When no longer needed, you can use the [az group delete](/cli/azure/group#az-group-delete) command to remove the resource group, load balancer, and all related resources.
158+
159+
```azurecli-interactive
160+
az group delete --name myresourcegroupoutbound
161+
```
162+
163+
## Next steps
164+
In this article, you created Standard Load Balancer, configured both inbound load balancer traffic rules, configured and health probe for the VMs in the backend pool. To learn more about Azure Load Balancer, continue to the tutorials for Azure Load Balancer.
165+
166+
> [!div class="nextstepaction"]
167+
> [Azure Load Balancer tutorials](tutorial-load-balancer-standard-public-zone-redundant-portal.md)

0 commit comments

Comments
 (0)