Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
In this quickstart, learn how to create a network address translation (NAT) gateway for the StandardV2 SKU of Azure NAT Gateway by using the Azure portal, Azure PowerShell, or the Azure CLI. The Azure NAT Gateway service provides scalable outbound connectivity for virtual machines in Azure.
Prerequisites
- An Azure account with an active subscription. Create an account for free.
Create a resource group
Create a resource group to contain all resources for this quickstart.
Sign in to the Azure portal.
In the search box at the top of the portal, enter Resource group. Select Resource groups in the search results.
Select + Create.
On the Basics tab of Create a resource group, enter or select the following information.
Setting Value Subscription Select your subscription. Resource group Enter test-rg. Region Enter East US. Select Review + create.
Select Create.
Create the NAT gateway
In this section, create the NAT gateway and supporting resources.
Azure NAT Gateway supports multiple deployment options for IP addresses and redundancy configurations to meet your connectivity and availability requirements.
Zone-redundant IPv4 address
Sign in to the Azure preview portal.
In the search box at the top of the portal, enter Public IP address. Select Public IP addresses in the search results.
Select Create.
In Create public IP address, enter the following information.
Setting Value Project details Subscription Select your subscription. Resource group Select your resource group. This example uses test-rg. Instance details Region Select a region. This example uses East US. Configuration details Name Enter public-ip-nat. IP version Select IPv4. SKU Select Standard V2 (For use with Standard V2 NAT Gateway). Tier Select Regional. Select Review + create, and then select Create.
In the search box at the top of the Azure portal, enter NAT gateway. Select NAT gateways in the search results.
Select Create.
On the Basics tab of Create network address translation (NAT) gateway, enter or select the following information.
Setting Value Project details Subscription Select your subscription. Resource group Select test-rg or your resource group. Instance details NAT gateway name Enter nat-gateway. Region Select your region. This example uses East US. SKU Select Standard V2. TCP idle timeout (minutes) Leave the default of 4. Select Next.
On the Outbound IP tab, select + Add public IP addresses or prefixes.
In Add public IP addresses or prefixes, select Public IP addresses. Select the public IP address that you created earlier, public-ip-nat.
Select Save.
Select Review + create, and then select Create.
Zone-redundant IPv4 prefix
Sign in to the Azure preview portal.
In the search box at the top of the portal, enter Public IP prefix. Select Public IP Prefixes in the search results.
Select Create.
On the Basics tab of Create a public IP prefix, enter the following information.
Setting Value Project details Subscription Select your subscription. Resource group Select your resource group. This example uses test-rg. Instance details Name Enter public-ip-prefix-nat. Region Select your region. This example uses East US. Sku Select Standard V2. IP version Select IPv4. Prefix ownership Select Microsoft owned. Prefix size Select a prefix size. This example uses /28 (16 addresses). Select Review + create, and then select Create.
In the search box at the top of the Azure portal, enter NAT gateway. Select NAT gateways in the search results.
Select Create.
On the Basics tab of Create network address translation (NAT) gateway, enter or select the following information.
Setting Value Project details Subscription Select your subscription. Resource group Select test-rg or your resource group. Instance details NAT gateway name Enter nat-gateway. Region Select your region. This example uses East US. SKU Select Standard V2. TCP idle timeout (minutes) Leave the default of 4. Select Next.
On the Outbound IP tab, select + Add public IP addresses or prefixes.
In Add public IP addresses or prefixes, select Public IP prefixes. Select the public IP prefix that you created earlier, public-ip-prefix-nat.
Select Review + create, and then select Create.
Create virtual network and subnet configurations
Create the virtual network and subnets that you need for this quickstart.
In the search box at the top of the Azure portal, enter Virtual network. Select Virtual networks in the search results.
Select Create.
On the Basics tab of Create virtual network, enter or select the following information.
Setting Value Project details Subscription Select your subscription. Resource group Select test-rg or your resource group. Instance details Name Enter vnet-1. Region Select your region. This example uses East US. Select the IP Addresses tab, or select Next > Next.
In Subnets, select the default subnet.
In Edit subnet, enter or select the following information.
Setting Value Subnet purpose Leave the default. Name Enter subnet-1. Private subnet Enable private subnet (no default outbound access) Select the checkbox. Security NAT gateway Select nat-gateway. Select Save.
Select + Add a subnet.
In Add a subnet, enter or select the following information.
Setting Value Subnet purpose Select Azure Bastion. Leave the rest of the settings as default, and then select Add.
Select Review + create, and then select Create.
Create an Azure Bastion host
Create an Azure Bastion host to securely connect to the virtual machine.
In the search box at the top of the Azure portal, enter Bastion. Select Bastions in the search results.
Select Create.
On the Basics tab of Create a Bastion, enter or select the following information.
Setting Value Project details Subscription Select your subscription. Resource group Select test-rg or your resource group. Instance details Name Enter bastion. Region Select your region. This example uses East US. Tier Select Developer. Virtual network Select vnet-1. Subnet Select AzureBastionSubnet. Select Review + create, and then select Create.
The Azure Bastion host can take several minutes to deploy. Wait for the bastion host to deploy before you move on to the next section.
Create a virtual machine
In this section, you create a virtual machine to test the NAT gateway and verify the public IP address of the outbound connection.
The following command creates Secure Shell (SSH) keys for authentication. You need the private key later to sign in to the virtual machine through Azure Bastion.
The username and password credentials are required for the command. You don't use the password to sign in to the virtual machine.
In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.
Select Create > Virtual machine.
In Create a virtual machine, enter or select the following information on the Basics tab.
Setting Value Project details Subscription Select your subscription. Resource group Select test-rg or your resource group. Instance details Virtual machine name Enter vm-1. Region Select your region. This example uses East US. Availability options Leave the default of No infrastructure redundancy required. Security type Select Standard. Image Select Ubuntu Server 24.04 LTS - Gen2. Size Select a size. Authentication type Select SSH public key. Username Enter a username of your choice. You need this username to sign in to the virtual machine later. SSH public key source Select Generate new key pair. Key pair name Enter ssh-key. Public inbound ports Select None. Select Next: Disks, and then select Next: Networking.
On the Networking tab, enter or select the following information.
Setting Value Network interface Virtual network Select vnet-1. Subnet Select subnet-1. Public IP Select None. NIC network security group Select Basic. Public inbound ports Leave the default of None. Select Review + create, and then select Create.
Wait for the virtual machine creation to finish before you move on to the next section.
Important
Ensure that you download the SSH private key to the virtual machine. You need the private key to sign in to the virtual machine through Azure Bastion.
Test the NAT gateway
To test the NAT gateway, you first discover the public IP of the NAT gateway. You then connect to the test virtual machine and verify the outbound connection through the NAT gateway's public IP.
In the search box at the top of the portal, enter NAT gateway. Select NAT gateways in the search results.
Select nat-gateway.
Expand Settings, and then select Outbound IP.
Make note of the outbound IP address. Individual public IPs and public IP prefixes configured for the NAT gateway appear here.
In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.
Select vm-1.
On the Overview page, select Connect, and then select Connect via Bastion.
In the Authentication list, select SSH Private Key From Local File.
In Username, enter the username that you entered during virtual machine creation.
In Local File, select the SSH private key file that you downloaded earlier.
Select Connect.
In the Bash prompt, enter the following command:
curl ifconfig.meVerify that the IP address returned by the command matches the public IP address of the NAT gateway that you noted earlier.
azureuser@vm-1:~$ curl ifconfig.me 203.0.113.0.25
Clean up resources
When you finish using the resources that you created, you can delete the resource group and all its resources.
In the Azure portal, search for and select Resource groups.
On the Resource groups page, select the test-rg resource group.
On the test-rg page, select Delete resource group.
Enter test-rg in Enter resource group name to confirm deletion, and then select Delete.