You are currently viewing Create A NAT Gateway

Create A NAT Gateway

Create a NAT gateway

Hello Everyone

Welcome to CloudAffaire and this is Debjeet

In the last blog post, we have learned how to connect to an instance that is hosted in a private subnet.

https://cloudaffaire.com/connect-to-an-instance-in-a-private-subnet/

In this blog post, we are going to enable outbound internet connection for a private subnet using a NAT gateway. Below are the configuration details for this demo.

Create A NAT Gateway

Currently, both outbound and inbound internet traffic is disabled for our private subnet.

Create A NAT Gateway

Create a NAT gateway:

Step 1: Login to AWS console and navigate to ‘VPC’.

Create A NAT Gateway

Step 2: Navigate to ‘Elastic IPs’ and click ‘Allocate new address’.

Create A NAT Gateway

Note: NAT gateway requires an elastic IP address to function. You can also create the elastic IP address during NAT gateway creation.

Step 3: Click ‘Allocate’.

Create A NAT Gateway

Note: 1st generation AWS account comes with EC2-Classic as network solution which was later replaced by VPC. If your account is created before 2013-12-04 then you will get the option of EC2-Classic apart from VPC for elastic IP address scope.

One success message will be displayed, click ‘Close’.

Create A NAT Gateway

A new elastic IP address has been allocated.

Create A NAT Gateway

Next, we are going to create a NAT Gateway.

Step 4: Navigate to ‘NAT Gateways’ and click ‘Create NAT Gateway’.

Create A NAT Gateway

Step 5: Select the public subnet (subnet 2) and Elastic IP address that has been created in the previous step and click ‘Create a NAT Gateway’.

Create A NAT Gateway

Warning: Additional charges apply for NAT gateway.

One success message will be displayed. In order to use the NAT gateway, we need to make it visible to the route by making an entry for it. Click ‘Edit route tables’.

Create A NAT Gateway

Step 6: Select the route table for your private subnet (subnet 1) and click ‘Edit routes’ located under ‘Routes’.

Create A NAT Gateway

Step 7: Click ‘Add route’ and from the drop down select your Nat gateway as target. Provide 0.0.0.0/0 as destination and click ‘Save Routes’.

Create A NAT Gateway

One success message will be displayed, click ‘Close’.

Create A NAT Gateway

Route table successfully modified.

Create A NAT Gateway

Outbound internet connection successfully enabled for your private subnet.

Create A NAT Gateway

Cleanup: Nat Gateways are hourly charges hence delete it as soon as your setup is completed. You can use the below steps to delete the NAT gateway.

Delete the route entry for NAT gateway.

Create A NAT Gateway

Delete your NAT Gateway

Create A NAT Gateway

Release the elastic IP address

Create A NAT Gateway

Terminate both the instances that we have created so far.

Create A NAT Gateway

Post deletion our VPC configuration looks like below

Create A NAT Gateway

You can also delete your VPC.

Create A NAT Gateway

Note: We will use this same VPC for the next couple of blogs. If you wish to follow, then do not delete the VPC.

Hope you have enjoyed this blog post. In the next blog post, we are going to create a new subnet with IPv6 CIDR block.

To get more details on VPC, please refer below AWS documentation

https://docs.aws.amazon.com/vpc/index.html

 

This Post Has One Comment

  1. Avatar
    Natalia Libra

    Wow, this was cool. Keep writing this kind of blogs, you will get a lot of people to this blog if you continue working on this.

Leave a Reply