Skip to main content

03. VPC, Subnet, IG, NAT


πŸ›œ Amazon VPC Overview​

A VPC (Virtual Private Cloud) is your own private network inside AWS β€” an isolated section of the AWS Cloud where you can launch resources such as EC2 instances.

  • It’s region-specific β€” each AWS Region can have its own VPCs.
  • It provides full control over your networking environment, including:
    • IP address range (CIDR block)
    • Subnets
    • Route tables
    • Internet connectivity
    • Security (Security Groups & Network ACLs)

🌐 Subnets​

A Subnet is a segment within your VPC β€” it partitions your network into smaller sections.

Each subnet is:

  • Associated with one Availability Zone (AZ).
  • Used to organize resources based on accessibility.
Subnet TypeDescriptionTypical Usage
Public SubnetConnected to an Internet GatewayWeb servers, Load balancers
Private SubnetNo direct internet accessDatabases, Application servers
IAM Roles Example

🚦 Route Tables​

To define access to the internet and between subnets, we use Route tables.

Route Tables define how traffic flows within the VPC and outside of it.

  • Every subnet is associated with a route table.
  • Routes determine whether a subnet is public or private.

Example:

DestinationTargetMeaning
10.0.0.0/16localInternal traffic within VPC
0.0.0.0/0igw-123Route to the Internet (public subnet)
IAM Roles Example

🌍 Internet Gateway (IGW)​

An Internet Gateway allows resources in public subnets to:

  • Send traffic to the internet.
  • Receive traffic from the internet.

Key Points:

  • Must be attached to a VPC.
  • Public subnets have a route to the IGW.
  • Private subnets do not.

Example Route Table (Public Subnet):

DestinationTarget
0.0.0.0/0igw-12345

πŸ” NAT Gateway (Network Address Translation Gateway)​

A NAT Gateway allows instances in private subnets to:

  • Access the internet outbound only (e.g., OS updates, package downloads).
  • Remain inaccessible from the internet inbound.

Setup:

  1. Create a NAT Gateway in a public subnet.
  2. Add a route in the private subnet’s route table that points to the NAT Gateway.
  3. The NAT Gateway then forwards traffic through the Internet Gateway.

Example Route Table (Private Subnet):

DestinationTarget
0.0.0.0/0nat-67890

🧠 Example Architecture​

IAM Roles Example

Traffic Flow:

  1. Internet β†’ IGW β†’ Public Subnet β†’ Web Server.
  2. Web Server β†’ Private Subnet β†’ Database.
  3. Private Subnet β†’ NAT Gateway β†’ IGW β†’ Internet (for updates).

πŸ“Š Summary Table​

ComponentDescriptionInternet AccessTypical Placement
VPCVirtual private network in AWSControlled by designRegion-wide
SubnetLogical partition inside a VPCDepends on routingPer AZ
Internet GatewayEnables internet access for public subnetsβœ… Inbound + OutboundPublic Subnet
NAT GatewayAllows private subnets to access internet outboundβœ… Outbound onlyPublic Subnet

βœ… In short:

  • VPC = your private cloud network.
  • Subnets = logical divisions (public or private).
  • Internet Gateway = entry/exit to the internet.
  • NAT Gateway = outbound-only access for private subnets.