Blog

AWS VPC: How to create a private subnet

What is a private subnet?

Private Subnet in any VPC has no internet connectivity but is connected with other resources in same VPC.
It is useful for applications that store sensitive information that should not be exposed to world or to an instance that has database in it. In this, other public instance that has internet connectivity can transfer request to this server and share response received from this server to the world.

Let’s see how can we achieve that on AWS

  1. In AWS, in every region, you will see one default VPC is created. 
  2. With Default VPC You will also get subnets as the same amount of Availability zones that the region has. But all of them come with an Internet gateway attached.  
  3. Let’s make a private subnet 
    1. Go to VPC → Subnets → Create Subnet
    2. Add Name of your subnet, let me name it “Private_subnet”
    3. Select VPC (choose the one where your EC2 resides)
    4. Set Availability zone preference if you have any, otherwise keep it blank 
    5. Add IPv4 CIDR Block Range, it must be unique within your VPC. I have added it as 172.31.128.0/24, as all before that are occupied. 
  4. Let’s Create Private Route in Route table 
    1. Go to VPC → Route tables → Create Route table 
    2. Name it and add VPC that we are working on 
    3. Click on Create Route table 
    4. Go to Edit Route Table and remove the entry with internet gateway and click on save routes. 
  5. Let’s attach this route to newly created subnet 
    1. Click on subnet we just created
    2. Go to Actions → Edit Route table association → Choose newly created Route table with no Internet gateway attached. 
    3. Click on save.

Our private subnet is ready.

Leave a Comment