Monday, 10 June 2024

Create a NAT gateway using the Azure portal

 

Create a NAT gateway using the Azure portal

In this quickstart, learn how to create a NAT gateway by using the Azure portal. The NAT Gateway service provides outbound connectivity for virtual machines in Azure.

Diagram of resources created in nat gateway quickstart.

Prerequisites

Sign in to Azure

Sign in to the Azure portal with your Azure account.

Create a NAT gateway

Before you deploy the NAT gateway resource and the other resources, a resource group is required to contain the resources deployed. In the following steps, you create a resource group, NAT gateway resource, and a public IP address. You can use one or more public IP address resources, public IP prefixes, or both.

For information about public IP prefixes and a NAT gateway, see Manage NAT gateway.

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

  2. Select + Create.

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

    SettingValue
    Project Details
    SubscriptionSelect your Azure subscription.
    Resource GroupSelect Create new.
    Enter test-rg.
    Select OK.
    Instance details
    NAT gateway nameEnter nat-gateway
    RegionSelect East US 2
    Availability ZoneSelect No Zone.
    TCP idle timeout (minutes)Leave the default of 4.

    For information about availability zones and NAT gateway, see NAT gateway and availability zones.

  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:

    SettingValue
    Public IP addressesSelect Create a new public IP address.
    In Name, enter public-ip-nat.
    Select OK.
  6. Select the Review + create tab, or select the blue Review + create button at the bottom of the page.

  7. Select Create.

Create a virtual network and bastion host

The following procedure creates a virtual network with a resource subnet, an Azure Bastion subnet, and an Azure Bastion host.

  1. In the portal, search for and select Virtual networks.

  2. On the Virtual networks page, select + Create.

  3. On the Basics tab of Create virtual network, enter or select the following information:

    SettingValue
    Project details
    SubscriptionSelect your subscription.
    Resource groupSelect test-rg.
    Instance details
    NameEnter vnet-1.
    RegionSelect East US 2.

    Screenshot of Basics tab of Create virtual network in the Azure portal.

  4. Select Next to proceed to the Security tab.

  5. Select Enable Bastion in the Azure Bastion section of the Security tab.

    Azure Bastion uses your browser to connect to VMs in your virtual network over secure shell (SSH) or remote desktop protocol (RDP) by using their private IP addresses. The VMs don't need public IP addresses, client software, or special configuration. For more information about Azure Bastion, see Azure Bastion


  6. Enter or select the following information in Azure Bastion:

    SettingValue
    Azure Bastion host nameEnter bastion.
    Azure Bastion public IP addressSelect Create a public IP address.
    Enter public-ip in Name.
    Select OK.

    Screenshot of enable bastion host in Create virtual network in the Azure portal.

  7. Select Next to proceed to the IP Addresses tab.

  8. In the address space box in Subnets, select the default subnet.

  9. In Edit subnet, enter or select the following information:

    SettingValue
    Subnet details
    Subnet templateLeave the default Default.
    NameEnter subnet-1.
    Starting addressLeave the default of 10.0.0.0.
    Subnet sizeLeave the default of /24(256 addresses).
    Security
    NAT gatewaySelect nat-gateway.

    Screenshot of default subnet rename and configuration.

  10. Select Save.

  11. Select Review + create at the bottom of the screen, and when validation passes, select Create.

Create test virtual machine

The following procedure creates a test virtual machine (VM) named vm-1 in the virtual network.

  1. In the portal, search for and select Virtual machines.

  2. In Virtual machines, select + Create, then Azure virtual machine.

  3. On the Basics tab of Create a virtual machine, enter or select the following information:

    SettingValue
    Project details
    SubscriptionSelect your subscription.
    Resource groupSelect test-rg.
    Instance details
    Virtual machine nameEnter vm-1.
    RegionSelect East US 2.
    Availability optionsSelect No infrastructure redundancy required.
    Security typeLeave the default of Standard.
    ImageSelect Ubuntu Server 22.04 LTS - x64 Gen2.
    VM architectureLeave the default of x64.
    SizeSelect a size.
    Administrator account
    Authentication typeSelect Password.
    UsernameEnter azureuser.
    PasswordEnter a password.
    Confirm passwordReenter the password.
    Inbound port rules
    Public inbound portsSelect None.
  4. Select the Networking tab at the top of the page.

  5. Enter or select the following information in the Networking tab:

    SettingValue
    Network interface
    Virtual networkSelect vnet-1.
    SubnetSelect subnet-1 (10.0.0.0/24).
    Public IPSelect None.
    NIC network security groupSelect Advanced.
    Configure network security groupSelect Create new.
    Enter nsg-1 for the name.
    Leave the rest at the defaults and select OK.
  6. Leave the rest of the settings at the defaults and select Review + create.

  7. Review the settings and select Create.

 

The default outbound access IP is disabled when one of the following events happens:

  • A public IP address is assigned to the VM.
  • The VM is placed in the backend pool of a standard load balancer, with or without outbound rules.
  • An Azure NAT Gateway resource is assigned to the subnet of the VM.

VMs that you create by using virtual machine scale sets in flexible orchestration mode don't have default outbound access.

For more information about outbound connections in Azure, see Default outbound access in Azure and Use Source Network Address Translation (SNAT) for outbound connections.

Test NAT gateway

In this section, you 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.

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

  2. Select public-ip-nat.

  3. Make note of the public IP address:

    Discover public IP address of NAT gateway

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

  5. Select vm-1.

  6. On the Overview page, select Connect, then select the Bastion tab.

  7. Select Use Bastion.

  8. Enter the username and password entered during VM creation. Select Connect.

  9. In the bash prompt, enter the following command:

    Bash
    curl ifconfig.me
    
  10. Verify the IP address returned by the command matches the public IP address of the NAT gateway.

    Outputazureuser@vm-1:~$ curl ifconfig.me
    20.7.200.36

No comments:

Post a Comment