Skip to main content

Kodekloud - 100 Days of cloud (AWS) Day 30: Enable Internet Access for Private EC2 using NAT Instance

Published 2 min readMarkdown

Step 1: Login into the AWS environment using provided credentials.

Step 2:

  • Go to VPC section and create a public subnet ,select the private VPC as mentioned.

  • Choose the zone and provide the CIDR range.

Step 3:

  • Create an Internet Gateway for internet access to public subnet.

  • Attach it to VPC.

Step 4: Configure route table and add Internet Gateway so that traffic reaches the subnet.

Step 5:

  • Go to EC2 section and you should create instance shown below.

  • Name it and select the Amazon Linux 2 AMI only as mentioned below.

  • Edit the VPC settings. as shown below.

  • Add IP of the private subnet to instance sg.

Step 6: Connect to the instance and carry out the following commands

  • sudo sysctl net.ipv4.ip_forward - Linux kernel is allowed to forward packets between network interfaces.

  • sudo sysctl -w net.ipv4.ip_forward=1 - Enabling NAT forwarding

  • sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE - entry of iptables

  • sudo yum install -y iptables-services - install iptable service

  • sudo service iptables save - save the rule and Linux forwards packets even after reboot.

Step 7: Add private subnet route table and add instance to it.

Step 8: Go to S3 and open the bucket and check for the file if it is uploaded or not.

No comments yet. Be the first to comment.