Create an AWS VPC with public and private subnets with NAT gateway.

In this article we will create a new vpc in AWS with public and private subnets along with NAT gateway, public and private route tables. so that, the private subnets have internet access and public subnets only exposed to the public access

1. create a new VPC

sign in to your aws account and go to the vpc section. click create vpc

create a vpc with above settings. choose a cidr block for IPV4 as 10.0.0.0/16 and tenancy with default

2.Public Subnet

Next, create a public subnet with the below configurations.  choose a cidr block for IPV4 as 10.0.1.0/24

modify public subnet settings by enabling Auto-assign IP  as below

3. Create private subnet

Next, create a public subnet with the below configurations.  choose a cidr block for IPV4 as 10.0.2.0/24

4. Attach Internet Gateway

create an Internet gateway and attach it to the vpc as below

  • Create Internet gateway.
  • click Actions dropdown button and select attach vpc to attach internet gateway to your vpc.

5. Create NAT Gateway

  • create NAT gateway in public subnet
  • attach elastic IP to the NAT Gateway

6. Create Public and Private Route Tables.

7. Add Internet Gateway and public subnet to Public Route Table

  • Click edit routes button under routes section in public Route Table
  • Add Internet Gateway to routes as below
  • After attaching the internet gateway, move to Subnet associations and click subnet associations button.
  • select public subnet and save association

8. Add NAT gateway and private subnet to Private Route Table

  • Click edit routes button under routes section in private Route Table
  • Add NAT Gateway to routes as below
  • After attaching the internet gateway, move to Subnet associations and click subnet associations button.
  • select public subnet and save association

That's it your VPC with public and private subnet is ready for production.

Subscribe to The MakInfraTek Blogs

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe