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.
Currently, both outbound and inbound internet traffic is disabled for our private subnet.
Create a NAT gateway:
Step 1: Login to AWS console and navigate to ‘VPC’.
Step 2: Navigate to ‘Elastic IPs’ and click ‘Allocate new address’.
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’.
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’.
A new elastic IP address has been allocated.
Next, we are going to create a NAT Gateway.
Step 4: Navigate to ‘NAT Gateways’ and click ‘Create 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’.
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’.
Step 6: Select the route table for your private subnet (subnet 1) and click ‘Edit routes’ located under ‘Routes’.
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’.
One success message will be displayed, click ‘Close’.
Route table successfully modified.
Outbound internet connection successfully enabled for your private subnet.
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.
Delete your NAT Gateway
Release the elastic IP address
Terminate both the instances that we have created so far.
Post deletion our VPC configuration looks like below
You can also delete your VPC.
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
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.