Nat-gateway
Good Morning everyone,
Just wanted to share a little hands-on experience I had setting up a NAT Gateway in AWS — it’s super helpful when you need your private EC2 instances to reach the internet (like for updates or pulling packages) without giving them a public IP or making them vulnerable.
🧭 Table of Contents
🔍 What is a NAT Gateway?
🧠 Why Use It?
🛠️ What I Set Up in AWS
📡 Route Table Configuration
✅ How I Verified It’s Working
🔐 Why This Setup Matters
🔍 What is a NAT Gateway?
A NAT (Network Address Translation) Gateway is a managed AWS service that allows instances in a private subnet to initiate outbound connections to the internet, while still preventing any inbound internet traffic from reaching them directly.
Think of it like a smart exit door for your private resources. They can get out (make requests), but no one from outside can get in through it.
🧠 Why Use It?
In real-world architectures, we often place sensitive resources (like databases, app servers, or internal APIs) in private subnets — away from public exposure. But sometimes, these resources still need to reach the internet:
For software updates
Pulling packages
Connecting to external APIs (like Stripe, GitHub, etc.)
A NAT Gateway solves this by giving them that access without compromising security.
🛠️ What I Set Up Using AWS Console
Here's what I built step-by-step:
✅ Created a Custom VPC
- CIDR Block:
10.0.0.0/16

✅ Added Two Subnets
Public Subnet →
10.0.1.0/24Private Subnet →
10.0.2.0/24


✅ Attached an Internet Gateway
Connected it to the custom VPC
This allows the public subnet to access the internet directly

✅ Launched a NAT Gateway
Deployed it in the public subnet
Allocated and attached an Elastic IP

✅ Updated Route Tables
Public Subnet → Route to Internet Gateway (IGW)
Private Subnet → Route all 0.0.0.0/0 traffic through the NAT Gateway


✅ Verifying It’s Working
To make sure everything was set up right:
I launched one EC2 instance in the public subnet and gave it a public IP
I launched another EC2 instance in the private subnet it has no public IP
Then I SSH into the public instance
From there, I SSH into the private instance
Finally, I ran:
ping google.com

🔐 Why NAT Gateway Matters
This setup is more than just cool — it’s a security best practice:
✅ Keeps your sensitive workloads isolated in private subnets
✅ Ensures they can still reach the outside world when needed
✅ Avoids assigning public IPs to critical infrastructure
✅ Aligns with cloud architecture principles and compliance standards
In production, this is an essential building block — especially if you're deploying microservices, backend APIs, or databases that shouldn’t be directly exposed.
📘 Summary
Setting up a NAT Gateway may sound complex at first, but once you grasp the network flow and properly configure the route tables, it becomes second nature. It’s a must-have for any secure, modern VPC setup on AWS.
Until next time, for all that jazz
— Shourya
Comments
Join the discussionNo comments yet. Be the first to comment.