Skip to main content

Command Palette

Search for a command to run...

Internet Gateway, NAT Gateway & Private Networking in AWS: Explained for DevOps Beginners

Understand how public and private networking actually works in AWS with clear examples and real-world DevOps use cases.

Published
Internet Gateway, NAT Gateway & Private Networking in AWS: Explained for DevOps Beginners
A
🚀 Code. Automate. Innovate. Hi, I’m Abdulrahman, a passionate DevOps Engineer and Software Developer on a mission to bridge the gap between code and production. With a love for automation, cloud-native solutions, and cutting-edge tech, I turn complex problems into seamless, scalable systems. 💡 What I Do: Build robust CI/CD pipelines that deliver software at the speed of thought. Architect cloud infrastructure that scales with a single command. Transform manual processes into automated workflows that just work. Break down silos and foster collaboration between teams. 🔧 Tech Stack I ❤️: Containers (Docker), Orchestration (Kubernetes), Infrastructure as Code (Terraform), CI/CD (Jenkins, GitLab), Cloud (AWS/GCP/Azure), and scripting like it’s my superpower. 📝 Why This Blog? This is where I share my journey, lessons learned, and the latest trends in DevOps and software engineering. Whether you're a seasoned pro or just starting out, join me as we explore the tools, tricks, and best practices that make the tech world tick. 🌟 Let’s Build the Future, One Pipeline at a Time. Connect with me, share your thoughts, and let’s automate the world together!

🎯 Target Audience: Beginners in DevOps & DevSecOps
🧠 Key Concepts: Internet Gateway, NAT Gateway, Private Subnets, Routing, Security
Estimated Read Time: ~10 minutes
📚 Series: Part of “AWS & Cloud Computing for DevOps Beginners”
🌍 Real-World Focus: How apps in AWS talk to the internet safely and securely


Why This Matters in DevOps

If you’re building on AWS, networking mistakes can break everything, even if your EC2s, S3s, and IAMs are perfect.

Every DevOps engineer needs to understand how private and public traffic flows in AWS, and how gateways (Internet + NAT) make that possible.

Because here’s the truth:
When your CI/CD runner, web app, or database can’t connect to the internet, it’s usually not DNS… It’s your VPC routing 😅.


1️⃣ Internet Gateway (IGW): Your Door to the Internet

An Internet Gateway is like your office’s main door; it allows people (traffic) to go in and out.

Without it, your AWS environment is fully isolated.

💡 In simple terms:

IGW = Lets instances in public subnets talk to the internet directly.


How It Works:

  1. You attach an IGW to your VPC.

  2. Add a route in your public route table:

     Destination: 0.0.0.0/0
     Target: igw-123456
    
  3. Any instance in that subnet with a public IP can now access the internet.

💡 Pro Tip:
For public access (like web servers), your subnet must:

  • Have a route to IGW ✅

  • Have Auto-assign Public IP enabled ✅

  • Use a Security Group allowing inbound traffic (e.g., port 80/443) ✅


Real-World Use Case:

Hosting a frontend web app on EC2.
Your users access it via the internet, so it must live in a public subnet connected to the IGW.


2️⃣ NAT Gateway: Internet Access for Private Subnets

Now imagine this:
Your backend app or database (in a private subnet) needs to download packages or connect to APIs, but shouldn’t be publicly accessible.

That’s where the NAT Gateway (Network Address Translation Gateway) steps in.


💡 What It Does:

NAT Gateway lets private resources access the internet outbound only without exposing them publicly.

It acts like a middleman:

  • Instances send traffic to NAT.

  • NAT forwards requests to the Internet using its own public IP.

  • Replies come back, and NAT routes them back inside.


How to Set It Up:

  1. Create a NAT Gateway in your public subnet.

  2. Attach an Elastic IP (for public internet access).

  3. In your private route table, add:

     Destination: 0.0.0.0/0
     Target: nat-123456
    
  4. Now private EC2s can access the internet outbound only 🌐.


Real-World Example:

Let’s say:

  • You have a web app (public subnet).

  • It connects to a database (private subnet).

  • The DB needs to download updates from the internet securely.

👉 NAT Gateway makes that possible without exposing the DB.


3️⃣ Public vs Private Subnets: The Big Picture

FeaturePublic SubnetPrivate Subnet
Internet Access✅ via IGW✅ outbound via NAT
Public IPsRequiredNot assigned
Typical UseWeb servers, bastion hostsDatabases, backend apps
Route Table0.0.0.0/0 → IGW0.0.0.0/0 → NAT

💡 DevOps Insight:
Designing your subnet layout this way is the backbone of secure cloud architectures. It separates what’s public and what’s private, like a firewall blueprint.


4️⃣ Real DevOps Scenario: Two-Tier Architecture

Here’s a quick practical breakdown:

Traffic flow:

  • Web app → publicly reachable.

  • Database → hidden, but can reach the internet via NAT for updates.

💡 This is the most common AWS VPC setup in production-ready architectures.


5️⃣ Common Mistakes to Avoid

⚠️ Creating NAT Gateway in private subnet (it must be public).
⚠️ Forgetting to attach the Elastic IP to the NAT.
⚠️ Missing route to IGW in the public subnet.
⚠️ Assuming private EC2s have internet access by default, they don’t!


6️⃣ Bonus Tip: NAT Gateway Costs

NAT Gateway isn’t free; it charges for:

  • Gateway hours

  • Data processed

If you’re practicing, try a NAT Instance (a small EC2 instance configured as a NAT); it's cheaper for labs and learning.

📘 AWS Docs: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html


Quick Recap

Internet Gateway → Direct access to the internet for public subnets.
NAT Gateway → Secure outbound access for private subnets.
Private Networking → Keep sensitive components isolated and protected.


Now that you understand gateways and private networking, try building your own 2-tier VPC with both IGW and NAT.

When your first “private EC2” connects to the internet through NAT, that’s your true DevOps networking milestone.

👉 Next up: AWS Security in Action: Layered Defense for DevOps Pipelines. 🔒


👨‍💻 Written by: Abdulrahman A. Muhamad
🌐 LinkedIn | GitHub | Portfolio

AWS for DevOps Beginners: From Basics to DevSecOps

Part 6 of 9

Beginner-to-advanced AWS series for DevOps engineers. Learn cloud basics, IAM, compute, networking, storage, databases, monitoring, IaC, CI/CD & DevSecOps with hands-on workflows to grow from AWS newbie to confident pro.

Up next

Security Groups & NACLs Explained for DevOps Beginners

Learn how Security Groups and Network ACLs work inside AWS VPCs — with simple analogies, real DevOps scenarios, diagrams, and interview questions.