Skip to main content

Command Palette

Search for a command to run...

Create a Custom VPC with Public and Private Subnets

Published
3 min read
Create a Custom VPC with Public and Private Subnets
C

Hi there! 👋 I'm Daniel Ozoemena, a passionate Cloud Solution Architect and DevOps Engineer dedicated to building scalable, secure, and innovative cloud solutions. With hands-on experience in Azure, AWS, and Google Cloud Platform, I specialize in deploying infrastructure as code, automating workflows, and optimizing system reliability. Driven by a love for problem-solving, I constantly explore new technologies and best practices to deliver impactful results. Beyond the cloud, I enjoy mentoring, blogging about tech insights, and contributing to open-source projects. When I'm not automating deployments or creating secure virtual networks, you can find me playing chess, learning about AI, or brainstorming solutions to real-world challenges. Let’s connect and grow together on this tech journey! 🚀

Objective: Learn how to create a custom VPC, set up subnets, and configure routing.


Step 1: Create a Custom VPC

  1. Sign in to the AWS Management Console.

  2. Navigate to VPC Dashboard.

  3. Click on Create VPC.

  4. Select VPC only and click Next.

  5. Enter the following details:

    • Name tag: MyCustomVPC

    • IPv4 CIDR block: 10.0.0.0/16

    • Leave other settings as default.

  6. Click Create VPC.


Step 2: Create Public and Private Subnets

  1. Go to Subnets (in the left panel).

  2. Click Create Subnet.

  3. Select MyCustomVPC from the VPC dropdown.

Create a Public Subnet

  1. Enter:

    • Name tag: PublicSubnet

    • Availability Zone: Select any one

    • IPv4 CIDR block: 10.0.1.0/24

  2. Click Create subnet.

Create a Private Subnet

  1. Click Create Subnet again.

  2. Enter:

    • Name tag: PrivateSubnet

    • Availability Zone: Select the same or different one

    • IPv4 CIDR block: 10.0.2.0/24

  3. Click Create subnet.


Step 3: Create an Internet Gateway and Attach to the VPC

  1. Go to Internet Gateways.

  2. Click Create internet gateway.

  3. Enter Name tag: MyIGW and click Create.

  4. Select the created Internet Gateway, click Actions → Attach to VPC.

  5. Choose MyCustomVPC and click Attach internet gateway.


Step 4: Create a Route Table for the Public Subnet

  1. Go to Route Tables.

  2. Click Create Route Table.

  3. Enter:

    • Name tag: PublicRouteTable

    • VPC: Select MyCustomVPC

  4. Click Create.

  5. Select the created route table → Click Routes → Edit routes.

  6. Click Add route and enter:

    • Destination: 0.0.0.0/0

    • Target: Select Internet Gateway (MyIGW)

  7. Click Save changes.

  8. Click Subnet Associations → Edit subnet associations.

  9. Select PublicSubnet → Click Save.


Step 5: Create a Route Table for the Private Subnet

  1. Repeat the steps for creating a Route Table but name it PrivateRouteTable.

  2. No need to add a 0.0.0.0/0 route, as private subnets don’t need direct internet access.

  3. Associate PrivateSubnet with PrivateRouteTable.


Step 6: Launch an EC2 Instance in the Public Subnet

  1. Go to EC2 Dashboard → Launch Instance.

  2. Choose Amazon Linux 2 as the AMI.

  3. Select t2.micro instance type and click Next.

  4. In Network settings:

    • VPC: Select MyCustomVPC

    • Subnet: Select PublicSubnet

    • Auto-assign Public IP: Enable

  5. Click Next → Add Storage → Next.

  6. Click Next → Configure Security Group:

    • Allow SSH (22) from Your IP

    • Allow HTTP (80) from Anywhere

  7. Click Review and Launch → Launch.

  8. Select/Create a key pair and launch the instance.


Step 7: Connect to the EC2 Instance

  1. Go to Instances and select the running EC2 instance.

  2. Copy the Public IPv4 address.

Open a terminal and connect using SSH:
bash

ssh -i my-key.pem ec2-user@<public-ip>

  1. You are now inside your EC2 instance! 🎉

More from this blog

Everything Cloud Solution

49 posts