Rediger

Quickstart: Create a StandardV2 NAT gateway

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

Create a resource group

Create a resource group to contain all resources for this quickstart.

  1. Sign in to the Azure portal.

  2. In the search box at the top of the portal, enter Resource group. Select Resource groups in the search results.

  3. Select + Create.

  4. 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.
  5. Select Review + create.

  6. 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

  1. Sign in to the Azure preview portal.

  2. In the search box at the top of the portal, enter Public IP address. Select Public IP addresses in the search results.

  3. Select Create.

  4. 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.
  5. Select Review + create, and then select Create.

  6. In the search box at the top of the Azure portal, enter NAT gateway. Select NAT gateways in the search results.

  7. Select Create.

  8. 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.
  9. Select Next.

  10. On the Outbound IP tab, select + Add public IP addresses or prefixes.

  11. In Add public IP addresses or prefixes, select Public IP addresses. Select the public IP address that you created earlier, public-ip-nat.

  12. Select Save.

  13. Select Review + create, and then select Create.

Zone-redundant IPv4 prefix

  1. Sign in to the Azure preview portal.

  2. In the search box at the top of the portal, enter Public IP prefix. Select Public IP Prefixes in the search results.

  3. Select Create.

  4. 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).
  5. Select Review + create, and then select Create.

  6. In the search box at the top of the Azure portal, enter NAT gateway. Select NAT gateways in the search results.

  7. Select Create.

  8. 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.
  9. Select Next.

  10. On the Outbound IP tab, select + Add public IP addresses or prefixes.

  11. In Add public IP addresses or prefixes, select Public IP prefixes. Select the public IP prefix that you created earlier, public-ip-prefix-nat.

  12. 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.

  1. In the search box at the top of the Azure portal, enter Virtual network. Select Virtual networks in the search results.

  2. Select Create.

  3. 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.
  4. Select the IP Addresses tab, or select Next > Next.

  5. In Subnets, select the default subnet.

  6. 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.
  7. Select Save.

  8. Select + Add a subnet.

  9. In Add a subnet, enter or select the following information.

    Setting Value
    Subnet purpose Select Azure Bastion.
  10. Leave the rest of the settings as default, and then select Add.

  11. Select Review + create, and then select Create.

Create an Azure Bastion host

Create an Azure Bastion host to securely connect to the virtual machine.

  1. In the search box at the top of the Azure portal, enter Bastion. Select Bastions in the search results.

  2. Select Create.

  3. 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.
  4. 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.

  1. In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.

  2. Select Create > Virtual machine.

  3. 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.
  4. Select Next: Disks, and then select Next: Networking.

  5. 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.
  6. 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.

  1. In the search box at the top of the portal, enter NAT gateway. Select NAT gateways in the search results.

  2. Select nat-gateway.

  3. Expand Settings, and then select Outbound IP.

  4. Make note of the outbound IP address. Individual public IPs and public IP prefixes configured for the NAT gateway appear here.

  5. In the search box at the top of the portal, enter Virtual machine. Select Virtual machines in the search results.

  6. Select vm-1.

  7. On the Overview page, select Connect, and then select Connect via Bastion.

  8. In the Authentication list, select SSH Private Key From Local File.

  9. In Username, enter the username that you entered during virtual machine creation.

  10. In Local File, select the SSH private key file that you downloaded earlier.

  11. Select Connect.

  12. In the Bash prompt, enter the following command:

    curl ifconfig.me
    
  13. Verify 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.

  1. In the Azure portal, search for and select Resource groups.

  2. On the Resource groups page, select the test-rg resource group.

  3. On the test-rg page, select Delete resource group.

  4. Enter test-rg in Enter resource group name to confirm deletion, and then select Delete.