I wanted to get hands-on with AWS networking and understand how private EC2 instances can be accessed without exposing them directly to the internet.

So I built a simple setup using a Bastion Host.

Architecture

The setup consists of:

  • A VPC
  • A public subnet hosting a Bastion EC2 instance
  • A private subnet hosting another EC2 instance
  • An Internet Gateway
  • Separate route tables
  • Security Groups controlling SSH access

The connection flow looks like this:

My Mac → Internet → Internet Gateway → Bastion Host → Private EC2

Network Configuration

I configured separate route tables for the public and private subnets.

Public Subnet

The public subnet's route table contains:

Destination Target
VPC CIDR Local
0.0.0.0/0 Internet Gateway

This allows resources in the public subnet to communicate with the internet, provided they have a public IP and the required security rules.

Private Subnet

The private subnet's route table contains only the local VPC route.

The private EC2 instance has no public IP and isn't directly accessible from the internet.

Security Groups

I configured the Security Groups to allow only the required SSH access.

Bastion Host

  • Inbound SSH (port 22) restricted to my IP address.

Private EC2

  • Inbound SSH (port 22) allowed only from the Bastion Host's Security Group.

This avoids exposing SSH on the private instance to the internet.

Connecting

From my Mac, I connected to the Bastion Host:

ssh -A -i key-pair.pem ec2-user@<BASTION_PUBLIC_IP> 

Once connected, I SSHed into the private EC2 instance using its private IP:

ssh ec2-user@<PRIVATE_IP> 

And I was finally inside the private instance.

What I Learned

This hands-on lab helped me understand how AWS networking components work together:

  • VPCs and CIDR: Defining network address ranges.
  • Subnets: Separating public and private resources.
  • Route Tables: Controlling traffic paths.
  • Internet Gateway: Enabling internet connectivity for public resources.
  • Security Groups: Controlling access between resources.
  • Bastion Hosts: Providing a controlled entry point to private infrastructure.

The key takeaway was that connectivity isn't determined by Security Groups alone. Routing, subnet configuration, IP addressing, and firewall rules all need to work together.

Next, I want to explore NAT Gateways and understand how private instances can access the internet without accepting inbound connections.

This was a hands-on learning lab as part of my journey into AWS and cloud networking.