Tutorial: Create a NAT gateway using the Azure portal

This tutorial shows you how to use Azure Virtual Network NAT service. You'll create a NAT gateway to provide outbound connectivity for a virtual machine in Azure.

In this tutorial, you learn how to:

  • Create a virtual network.
  • Create a virtual machine.
  • Create a NAT gateway and associate with the virtual network.
  • Connect to virtual machine and verify NAT IP address.

Prerequisites

Virtual network

Before you deploy a VM and can use your NAT gateway, we need to create the resource group and virtual network.

  1. Sign in to the Azure portal.

  2. On the upper-left side of the screen, select Create a resource > Networking > Virtual network or search for Virtual network in the search box.

  3. Select Create.

  4. In Create virtual network, enter or select this information in the Basics tab:

    Setting Value
    Project Details
    Subscription Select your Azure subscription
    Resource Group Select Create new.
    Enter myResourceGroupNAT.
    Select OK.
    Instance details
    Name Enter myVNet
    Region Select (Europe) West Europe
  5. Select the IP Addresses tab or select the Next: IP Addresses button at the bottom of the page.

  6. In the IP Addresses tab, enter this information:

    Setting Value
    IPv4 address space Enter 10.1.0.0/16
  7. Select + Add subnet.

  8. In Edit subnet, enter this information:

    Setting Value
    Subnet name Enter mySubnet
    Subnet address range Enter 10.1.0.0/24
  9. Select Add.

  10. Select the Security tab.

  11. Under BastionHost, select Enable. Enter this information:

    Setting Value
    Bastion name Enter myBastionHost
    AzureBastionSubnet address space Enter 10.1.1.0/24
    Public IP Address Select Create new.
    For Name, enter myBastionIP.
    Select OK.
  12. Select the Review + create tab or select the Review + create button.

  13. Select Create.

NAT gateway

You can use one or more public IP address resources, public IP prefixes, or both. We'll add a public IP resource and a NAT gateway resource.

  1. On the upper-left side of the screen, select Create a resource > Networking > NAT gateway or search for NAT gateway in the search box.

  2. Select Create.

  3. In Create network address translation (NAT) gateway, enter or select this information in the Basics tab:

    Setting Value
    Project Details
    Subscription Select your Azure subscription.
    Resource Group Select myResourceGroupNAT.
    Instance details
    Name Enter myNATgateway
    Region Select (Europe) West Europe
    Availability Zone Select None.
    Idle timeout (minutes) Enter 10.
  4. Select the Outbound IP tab, or select the Next: Outbound IP button at the bottom of the page.

  5. In the Outbound IP tab, enter or select the following information:

    Setting Value
    Public IP addresses Select Create a new public IP address.
    In Name, enter myPublicIP.
    Select OK.
  6. Select the Subnet tab, or select the Next: Subnet button at the bottom of the page.

  7. In the Subnet tab, select myVNet in the Virtual network pull-down.

  8. Check the box next to mySubnet.

  9. Select the Review + create tab, or select the blue Review + create button at the bottom of the page.

  10. Select Create.

Virtual machine

In this section, you'll create a virtual machine to test the NAT gateway and verify the public IP address of the outbound connection.

  1. On the upper-left side of the portal, select Create a resource > Compute > Virtual machine.

  2. In the Create a virtual machine page in the Basics tab, enter, or select the following information:

    Setting Value
    Project details
    Subscription Select your subscription.
    Resource group Select myResourceGroupNAT.
    Instance details
    Virtual machine name Enter myVM.
    Region Select (Europe) West Europe.
    Availability options Leave the default of no redundancy required.
    Image Select Windows Server 2019 Datacenter - Gen1.
    Size Select Standard_DS1_v2.
    Administrator account
    Username Enter a username for the virtual machine.
    Password Enter a password.
    Confirm password Confirm password.
    Inbound port rules
    Public inbound ports Select None.
  3. Select the Disks tab, or select the Next: Disks button at the bottom of the page.

  4. Leave the default in the Disks tab.

  5. Select the Networking tab, or select the Next: Networking button at the bottom of the page.

  6. In the Networking tab, enter or select the following information:

    Setting Value
    Network interface
    Virtual network Select myVNet.
    Subnet Select mySubnet.
    Public IP Select None.
    NIC network security group Select Basic.
    Public inbound ports Select None.
  7. Select the Review + create tab, or select the blue Review + create button at the bottom of the page.

  8. Select Create.

Test NAT gateway

In this section, we'll test the NAT gateway. We'll first discover the public IP of the NAT gateway. We'll then connect to the test virtual machine and verify the outbound connection through the NAT gateway.

  1. Find the public IP address for the NAT gateway on the Overview screen. Select All services in the left-hand menu, select All resources, and then select myPublicIP.

  2. Make note of the public IP address:

    Discover public IP address of NAT gateway

  3. Select All services in the left-hand menu, select All resources, and then from the resources list, select myVM that is located in the myResourceGroupNAT resource group.

  4. On the Overview page, select Connect, then Bastion.

  5. Select the blue Use Bastion button.

  6. Enter the username and password entered during VM creation.

  7. Open Internet Explorer on myTestVM.

  8. Enter https://whatsmyip.com in the address bar.

  9. Verify the IP address displayed matches the NAT gateway address you noted in the previous step:

    Internet Explorer showing external outbound IP

Clean up resources

If you're not going to continue to use this application, delete the virtual network, virtual machine, and NAT gateway with the following steps:

  1. From the left-hand menu, select Resource groups.

  2. Select the myResourceGroupNAT resource group.

  3. Select Delete resource group.

  4. Enter myResourceGroupNAT and select Delete.

Next steps

For more information on Azure Virtual Network NAT, see: