Skip to content

Commit 5f82b3c

Browse files
authored
Merge pull request #191036 from asudbring/lb-portforwardmulti-new
New article for multiple instance inbound NAT rule tutorial
2 parents dce26d3 + 4f32361 commit 5f82b3c

File tree

5 files changed

+358
-0
lines changed

5 files changed

+358
-0
lines changed

articles/load-balancer/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
href: tutorial-multi-availability-sets-portal.md
3434
- name: Create a single instance inbound NAT rule
3535
href: tutorial-load-balancer-port-forwarding-portal.md
36+
- name: Create a multiple instance inbound NAT rule
37+
href: tutorial-nat-rule-multi-instance-portal.md
3638
- name: Load balance multiple IP configurations
3739
href: load-balancer-multiple-ip.md
3840
- name: Cross-region load balancer
444 KB
Loading
94.7 KB
Loading
52.1 KB
Loading
Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
---
2+
title: "Tutorial: Create a multiple instance inbound NAT rule - Azure portal"
3+
titleSuffix: Azure Load Balancer
4+
description: This tutorial shows how to configure port forwarding using Azure Load Balancer to create a connection to multiple virtual machines in an Azure virtual network.
5+
author: asudbring
6+
ms.author: allensu
7+
ms.service: load-balancer
8+
ms.topic: tutorial
9+
ms.date: 03/10/2022
10+
ms.custom: template-tutorial
11+
---
12+
13+
# Tutorial: Create a multiple instance inbound NAT rule using the Azure portal
14+
15+
Inbound NAT rules allow you to connect to virtual machines (VMs) in an Azure virtual network by using an Azure Load Balancer public IP address and port number.
16+
17+
For more information about Azure Load Balancer rules, see [Manage rules for Azure Load Balancer using the Azure portal](manage-rules-how-to.md).
18+
19+
In this tutorial, you learn how to:
20+
21+
> [!div class="checklist"]
22+
> * Create a virtual network and virtual machines
23+
> * Create a standard SKU public load balancer with frontend IP, health probe, backend configuration, and load-balancing rule
24+
> * Create a multiple instance inbound NAT rule
25+
> * Create a NAT gateway for outbound internet access for the backend pool
26+
> * Install and configure a web server on the VMs to demonstrate the port forwarding and load-balancing rules
27+
28+
## Prerequisites
29+
30+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
31+
32+
## Create virtual network and virtual machines
33+
34+
A virtual network and subnet is required for the resources in the tutorial. In this section, you'll create a virtual network and virtual machines for the later steps.
35+
36+
1. Sign in to the [Azure portal](https://portal.azure.com).
37+
38+
2. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
39+
40+
3. In **Virtual machines**, select **+ Create** > **+ Virtual machine**.
41+
42+
4. In **Create a virtual machine**, enter or select the following values in the **Basics** tab:
43+
44+
| Setting | Value |
45+
| ------- | ----- |
46+
| **Project details** | |
47+
| Subscription | Select your subscription. |
48+
| Resource group | Select **Create new**. </br> Enter **TutorialLBPF-rg**. </br> Select **OK**. |
49+
| **Instance details** | |
50+
| Virtual machine name | Enter **myVM1**. |
51+
| Region | Enter **(US) West US 2**. |
52+
| Availability options | Select **Availability zone**. |
53+
| Availability zone | Enter **1**. |
54+
| Security type | Select **Standard**. |
55+
| Image | Select **Ubuntu Server 20.04 LTS - Gen2**. |
56+
| Azure Spot instance | Leave the default of unchecked. |
57+
| Size | Select a VM size. |
58+
| **Administrator account** | |
59+
| Authentication type | Select **SSH public key**. |
60+
| Username | Enter **azureuser**. |
61+
| SSH public key source | Select **Generate new key pair**. |
62+
| Key pair name | Enter **myKey**. |
63+
| **Inbound port rules** | |
64+
| Public inbound ports | Select **None**. |
65+
66+
5. Select the **Networking** tab, or select **Next: Disks**, then **Next: Networking**.
67+
68+
6. In the **Networking** tab, enter or select the following information.
69+
70+
| Setting | Value |
71+
| ------- | ----- |
72+
| **Network interface** | |
73+
| Virtual network | Select **Create new**. </br> Enter **myVNet** in **Name**. </br> In **Address space**, under **Address range**, enter **10.1.0.0/16**. </br> In **Subnets**, under **Subnet name**, enter **myBackendSubnet**. </br> In **Address range**, enter **10.1.0.0/24**. </br> Select **OK**. |
74+
| Subnet | Select **myBackendSubnet**. |
75+
| Public IP | Select **None**. |
76+
| NIC network security group | Select **Advanced**. |
77+
| Configure network security group | Select **Create new**. </br> Enter **myNSG** in **Name**. </br> Select **+ Add an inbound rule** under **Inbound rules**. </br> In **Service**, select **HTTP**. </br> Enter **100** in **Priority**. </br> Enter **myNSGRule** for **Name**. </br> Select **Add**. </br> Select **OK**. |
78+
79+
7. Select the **Review + create** tab, or select the **Review + create** button at the bottom of the page.
80+
81+
8. Select **Create**.
82+
83+
9. At the **Generate new key pair** prompt, select **Download private key and create resource**. Your key file will be downloaded as myKey.pem. Ensure you know where the .pem file was downloaded, you'll need the path to the key file in later steps.
84+
85+
8. Follow the steps 1 through 8 to create another VM with the following values and all the other settings the same as **myVM1**:
86+
87+
| Setting | VM 2 |
88+
| ------- | ----- |
89+
| **Basics** | |
90+
| **Instance details** | |
91+
| Virtual machine name | **myVM2** |
92+
| Availability zone | **2** |
93+
| **Administrator account** | |
94+
| Authentication type | **SSH public key** |
95+
| SSH public key source | Select **Use existing key stored in Azure**. |
96+
| Stored Keys | Select **myKey**. |
97+
| **Inbound port rules** | |
98+
| Public inbound ports | Select **None**. |
99+
| **Networking** | |
100+
| **Network interface** | |
101+
| Public IP | Select **None**. |
102+
| NIC network security group | Select **Advanced**. |
103+
| Configure network security group | Select the existing **myNSG** |
104+
105+
## Create load balancer
106+
107+
You'll create a load balancer in this section. The frontend IP, backend pool, load-balancing, and inbound NAT rules are configured as part of the creation.
108+
109+
1. In the search box at the top of the portal, enter **Load balancer**. Select **Load balancers** in the search results.
110+
111+
2. In the **Load balancer** page, select **Create**.
112+
113+
3. In the **Basics** tab of the **Create load balancer** page, enter, or select the following information:
114+
115+
| Setting | Value |
116+
| --- | --- |
117+
| **Project details** | |
118+
| Subscription | Select your subscription. |
119+
| Resource group | Select **TutorialLBPF-rg**. |
120+
| **Instance details** | |
121+
| Name | Enter **myLoadBalancer** |
122+
| Region | Select **West US 2**. |
123+
| SKU | Leave the default **Standard**. |
124+
| Type | Select **Public**. |
125+
| Tier | Leave the default **Regional**. |
126+
127+
4. Select **Next: Frontend IP configuration** at the bottom of the page.
128+
129+
5. In **Frontend IP configuration**, select **+ Add a frontend IP**.
130+
131+
6. Enter **myFrontend** in **Name**.
132+
133+
7. Select **IPv4** or **IPv6** for the **IP version**.
134+
135+
> [!NOTE]
136+
> IPv6 isn't currently supported with Routing Preference or Cross-region load-balancing (Global Tier).
137+
138+
8. Select **IP address** for the **IP type**.
139+
140+
> [!NOTE]
141+
> For more information on IP prefixes, see [Azure Public IP address prefix](../virtual-network/ip-services/public-ip-address-prefix.md).
142+
143+
9. Select **Create new** in **Public IP address**.
144+
145+
10. In **Add a public IP address**, enter **myPublicIP** for **Name**.
146+
147+
11. Select **Zone-redundant** in **Availability zone**.
148+
149+
> [!NOTE]
150+
> In regions with [Availability Zones](../availability-zones/az-overview.md?toc=%2fazure%2fvirtual-network%2ftoc.json#availability-zones), you have the option to select no-zone (default option), a specific zone, or zone-redundant. The choice will depend on your specific domain failure requirements. In regions without Availability Zones, this field won't appear. </br> For more information on availability zones, see [Availability zones overview](../availability-zones/az-overview.md).
151+
152+
12. Leave the default of **Microsoft Network** for **Routing preference**.
153+
154+
13. Select **OK**.
155+
156+
14. Select **Add**.
157+
158+
15. Select **Next: Backend pools** at the bottom of the page.
159+
160+
16. In the **Backend pools** tab, select **+ Add a backend pool**.
161+
162+
17. Enter or select the following information in **Add backend pool**.
163+
164+
| Setting | Value |
165+
| ------- | ----- |
166+
| Name | Enter **myBackendPool**. |
167+
| Virtual network | Select **myVNet (TutorialLBPF-rg)**. |
168+
| Backend Pool Configuration | Select **NIC**. |
169+
| IP version | Select **IPv4**. |
170+
171+
18. Select **+ Add** in **Virtual machines**.
172+
173+
19. Select the checkboxes next to **myVM1** and **myVM2** in **Add virtual machines to backend pool**.
174+
175+
20. Select **Add**.
176+
177+
21. Select **Add**.
178+
179+
22. Select the **Next: Inbound rules** button at the bottom of the page.
180+
181+
23. In **Load balancing rule** in the **Inbound rules** tab, select **+ Add a load balancing rule**.
182+
183+
24. In **Add load balancing rule**, enter or select the following information.
184+
185+
| Setting | Value |
186+
| ------- | ----- |
187+
| Name | Enter **myHTTPRule** |
188+
| IP Version | Select **IPv4** or **IPv6** depending on your requirements. |
189+
| Frontend IP address | Select **myFrontend**. |
190+
| Backend pool | Select **myBackendPool**. |
191+
| Protocol | Select **TCP**. |
192+
| Port | Enter **80**. |
193+
| Backend port | Enter **80**. |
194+
| Health probe | Select **Create new**. </br> In **Name**, enter **myHealthProbe**. </br> Select **TCP** in **Protocol**. </br> Leave the rest of the defaults, and select **OK**. |
195+
| Session persistence | Select **None**. |
196+
| Idle timeout (minutes) | Enter or select **15**. |
197+
| TCP reset | Select **Enabled**. |
198+
| Floating IP | Select **Disabled**. |
199+
| Outbound source network address translation (SNAT) | Leave the default of **(Recommended) Use outbound rules to provide backend pool members access to the internet.** |
200+
201+
For more information about load-balancing rules, see [Load-balancing rules](manage-rules-how-to.md#load-balancing-rules).
202+
203+
25. Select **Add**.
204+
205+
26. Select the blue **Review + create** button at the bottom of the page.
206+
207+
27. Select **Create**.
208+
209+
## Create multiple instance inbound NAT rule
210+
211+
In this section, you'll create a multiple instance inbound NAT rule to the backend pool of the load balancer.
212+
213+
1. In the search box at the top of the portal, enter **Load balancer**. Select **Load balancers** in the search results.
214+
215+
2. Select **myLoadBalancer**.
216+
217+
3. In **myLoadBalancer**, select **Inbound NAT rules** in settings.
218+
219+
4. Select **+ Add** in **Inbound NAT rules**.
220+
221+
5. Enter or select the following information in **Add inbound NAT rule**.
222+
223+
| Setting | Value |
224+
| ------- | ----- |
225+
| Name | Enter **myNATRule-SSH**. |
226+
| Type | Select **Backend pool**. |
227+
| Target backend pool | Select **myBackendPool**. |
228+
| Frontend IP address | Select **myFrontend**. |
229+
| Frontend port range start | Enter **221**. |
230+
| Maximum number of machines in backend pool | Enter **500**. |
231+
| Backend port | Enter **22**. |
232+
| Protocol | Select **TCP**. |
233+
234+
6. Leave the rest at the default and select **Add**.
235+
236+
## Create NAT gateway
237+
238+
In this section, you'll create a NAT gateway for outbound internet access for resources in the virtual network.
239+
240+
For more information about outbound connections and Azure Virtual Network NAT, see [Using Source Network Address Translation (SNAT) for outbound connections](load-balancer-outbound-connections.md) and [What is Virtual Network NAT?](../virtual-network/nat-gateway/nat-overview.md).
241+
242+
1. In the search box at the top of the portal, enter **NAT gateway**. Select **NAT gateways** in the search results.
243+
244+
2. In **NAT gateways**, select **+ Create**.
245+
246+
3. In **Create network address translation (NAT) gateway**, enter or select the following information:
247+
248+
| Setting | Value |
249+
| ------- | ----- |
250+
| **Project details** | |
251+
| Subscription | Select your subscription. |
252+
| Resource group | Select **TutorialLBPF-rg**. |
253+
| **Instance details** | |
254+
| NAT gateway name | Enter **myNATgateway**. |
255+
| Region | Select **West US 2**. |
256+
| Availability zone | Select **None**. |
257+
| Idle timeout (minutes) | Enter **15**. |
258+
259+
4. Select the **Outbound IP** tab or select the **Next: Outbound IP** button at the bottom of the page.
260+
261+
5. In **Outbound IP**, select **Create a new public IP address** next to **Public IP addresses**.
262+
263+
6. Enter **myNATGatewayIP** in **Name** in **Add a public IP address**.
264+
265+
7. Select **OK**.
266+
267+
8. Select the **Subnet** tab or select the **Next: Subnet** button at the bottom of the page.
268+
269+
9. In **Virtual network** in the **Subnet** tab, select **myVNet**.
270+
271+
10. Select **myBackendSubnet** under **Subnet name**.
272+
273+
11. Select the blue **Review + create** button at the bottom of the page, or select the **Review + create** tab.
274+
275+
12. Select **Create**.
276+
277+
## Install web server
278+
279+
In this section, you'll SSH to the virtual machines through the inbound NAT rules and install a web server.
280+
281+
1. In the search box at the top of the portal, enter **Load balancer**. Select **Load balancers** in the search results.
282+
283+
2. Select **myLoadBalancer**.
284+
285+
3. Select **Fronted IP configuration** in **Settings**.
286+
287+
3. In the **Frontend IP configuration**, make note of the **IP address** for **myFrontend**. In this example, it's **20.99.165.176**.
288+
289+
:::image type="content" source="./media/tutorial-nat-rule-multi-instance-portal/get-public-ip.png" alt-text="Screenshot of public IP in Azure portal.":::
290+
291+
4. If you're using a Mac or Linux computer, open a Bash prompt. If you're using a Windows computer, open a PowerShell prompt.
292+
293+
5. At your prompt, open an SSH connection to **myVM1**. Replace the IP address with the address you retrieved in the previous step and port **221** you used for the myVM1 inbound NAT rule. Replace the path to the .pem with the path to where the key file was downloaded.
294+
295+
```console
296+
ssh -i .\Downloads\myKey.pem [email protected] -p 221
297+
```
298+
299+
> [!TIP]
300+
> The SSH key you created can be used the next time your create a VM in Azure. Just select the **Use a key stored in Azure** for **SSH public key source** the next time you create a VM. You already have the private key on your computer, so you won't need to download anything.
301+
302+
6. From your SSH session, update your package sources and then install the latest NGINX package.
303+
304+
```bash
305+
sudo apt-get -y update
306+
sudo apt-get -y install nginx
307+
```
308+
309+
7. Enter `Exit` to leave the SSH session
310+
311+
8. At your prompt, open an SSH connection to **myVM2**. Replace the IP address with the address you retrieved in the previous step and port **222** you used for the myVM2 inbound NAT rule. Replace the path to the .pem with the path to where the key file was downloaded.
312+
313+
```console
314+
ssh -i .\Downloads\myKey.pem [email protected] -p 222
315+
```
316+
317+
9. From your SSH session, update your package sources and then install the latest NGINX package.
318+
319+
```bash
320+
sudo apt-get -y update
321+
sudo apt-get -y install nginx
322+
```
323+
324+
10. Enter `Exit` to leave the SSH session.
325+
326+
## Test the web server
327+
328+
You'll open your web browser in this section and enter the IP address for the load balancer you retrieved in the previous step.
329+
330+
1. Open your web browser.
331+
332+
2. In the address bar, enter the IP address for the load balancer. In this example, it's **20.99.165.176**.
333+
334+
3. The default NGINX website is displayed.
335+
336+
:::image type="content" source="./media/tutorial-nat-rule-multi-instance-portal/web-server-test.png" alt-text="Screenshot of testing the NGINX web server.":::
337+
338+
## Clean up resources
339+
340+
If you're not going to continue to use this application, delete
341+
the virtual machines and load balancer with the following steps:
342+
343+
1. In the search box at the top of the portal, enter **Resource group**. Select **Resource groups** in the search results.
344+
345+
2. Select **TutorialLBPF-rg** in **Resource groups**.
346+
347+
3. Select **Delete resource group**.
348+
349+
4. Enter **TutorialLBPF-rg** in **TYPE THE RESOURCE GROUP NAME:**. Select **Delete**.
350+
351+
## Next steps
352+
353+
Advance to the next article to learn how to create a cross-region load balancer:
354+
355+
> [!div class="nextstepaction"]
356+
> [Create a cross-region load balancer using the Azure portal](tutorial-cross-region-portal.md)

0 commit comments

Comments
 (0)