DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

VPC, subnets, IGW, NAT, routing, firewall, DMZ, private DB, and troubleshooting part #1

πŸ”₯ LAB GOAL (PRODUCTION STYLE)

You will build:

Internet
   ↓
Load Balancer (DMZ / Public)
   ↓
Web Server (Private)
   ↓
Database (Private)
Enter fullscreen mode Exit fullscreen mode

With:

  • Public subnets (DMZ)
  • Private subnets (App + DB)
  • NAT Gateway
  • Security Groups (firewall)
  • Route tables (routing)

πŸš€ STEP 0 β€” WHAT YOU MUST HAVE

Already created:

βœ” VPC
βœ” 2 Public subnets
βœ” 2 Private subnets
βœ” Internet Gateway
βœ” NAT Gateway


πŸš€ STEP 1 β€” FIX ROUTING (VERY IMPORTANT)

Public Route Table

Go to VPC β†’ Route Tables β†’ Public RT

Make sure:

0.0.0.0/0 β†’ Internet Gateway
Enter fullscreen mode Exit fullscreen mode

Associate:

  • Public Subnet 1
  • Public Subnet 2

Private Route Table

Make sure:

0.0.0.0/0 β†’ NAT Gateway
Enter fullscreen mode Exit fullscreen mode

Associate:

  • Private Subnet 1
  • Private Subnet 2

βœ” Result:

  • Public = internet access
  • Private = outbound only

πŸš€ STEP 2 β€” CREATE SECURITY GROUPS (FIREWALL DESIGN)

1. Load Balancer SG (alb-sg)

Allow:

HTTP 80 β†’ 0.0.0.0/0
Enter fullscreen mode Exit fullscreen mode

2. Web Server SG (web-sg)

Allow:

HTTP 80 β†’ alb-sg
SSH 22 β†’ your IP
Enter fullscreen mode Exit fullscreen mode

3. Database SG (db-sg)

Allow:

MySQL 3306 β†’ web-sg
Enter fullscreen mode Exit fullscreen mode

βœ” Result:

  • Internet β†’ only ALB
  • ALB β†’ Web
  • Web β†’ DB
  • Users CANNOT access DB

πŸ‘‰ This is real firewall architecture


πŸš€ STEP 3 β€” CREATE LOAD BALANCER (DMZ)

Use:
Application Load Balancer

Where:

EC2 β†’ Load Balancers β†’ Create


Config:

  • Type: Application LB

  • Scheme: Internet-facing

  • Subnets:

    • Public Subnet 1
    • Public Subnet 2
  • Security Group:

    • alb-sg

βœ” Result:

πŸ‘‰ Entry point for users


πŸš€ STEP 4 β€” CREATE WEB SERVERS (PRIVATE)

Launch 2 EC2:

  • Subnet:

    • private-subnet-1
    • private-subnet-2
  • Security Group:

    • web-sg
  • NO public IP


Install nginx:

sudo apt update
sudo apt install nginx -y
Enter fullscreen mode Exit fullscreen mode

Customize page:

echo "Hello from Web Server 1" | sudo tee /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

βœ” Result:

πŸ‘‰ Private app servers running


πŸš€ STEP 5 β€” CONNECT ALB β†’ WEB

Create Target Group:

  • Type: Instance
  • Port: 80

Add both EC2 instances


Attach to Load Balancer


βœ” Result:

πŸ‘‰ ALB sends traffic to web servers


πŸš€ STEP 6 β€” TEST

Open:

http://<ALB-DNS>
Enter fullscreen mode Exit fullscreen mode

βœ” Result:

πŸ‘‰ You see your web page

Refresh:
πŸ‘‰ It switches between servers


πŸš€ STEP 7 β€” CREATE DATABASE (SIMULATION)

You can use EC2 or:
Amazon RDS


For simple lab (EC2 DB):

Launch EC2:

  • Subnet: private-subnet-1
  • SG: db-sg

βœ” Result:

πŸ‘‰ Private DB server


πŸš€ STEP 8 β€” TEST NETWORK SECURITY

Try:

From your laptop:

  • Access DB β†’ ❌ FAIL

From web EC2:

  • Connect DB β†’ βœ” WORK

πŸ‘‰ This proves firewall working


πŸš€ STEP 9 β€” TEST NAT (VERY IMPORTANT)

SSH into web EC2:

ping google.com
Enter fullscreen mode Exit fullscreen mode

βœ” Result:

πŸ‘‰ Works β†’ NAT is correct


πŸš€ STEP 10 β€” BREAK & DEBUG (SRE LEVEL)

Now simulate failures:


Scenario 1 β€” Remove NAT route

πŸ‘‰ Private EC2 cannot reach internet

Fix:
πŸ‘‰ Add NAT route back


Scenario 2 β€” Remove SG rule (web β†’ db)

πŸ‘‰ App cannot reach DB

Fix:
πŸ‘‰ Add rule back


Scenario 3 β€” Stop one EC2

πŸ‘‰ App still works via ALB


πŸ‘‰ This is real SRE behavior


πŸ”₯ WHAT YOU JUST LEARNED

You implemented:

βœ” VPC design
βœ” Subnet segmentation (DMZ / Private)
βœ” Routing (IGW + NAT)
βœ” Firewall (SG)
βœ” Load balancing
βœ” Secure DB access
βœ” Failure testing


πŸ’¬ INTERVIEW ANSWER

I built a multi-tier architecture in AWS with public and private subnets, configured routing using Internet Gateway and NAT Gateway, secured communication using security groups, deployed web servers behind an Application Load Balancer, and validated failover and connectivity through testing scenarios.

Top comments (0)