DEV Community

Cover image for Understanding AWS VPCs, Subnets, and Internet Gateways
Noor Fatima
Noor Fatima

Posted on

Understanding AWS VPCs, Subnets, and Internet Gateways

In Amazon Web Services (AWS), a Virtual Private Cloud (VPC) is a fundamental component that allows you to create a virtualized network within the AWS cloud. This article covers key aspects of VPCs, subnets, internet gateways, and route tables, and explains how to configure public and private subnets.
__

What is a VPC?

A VPC (Virtual Private Cloud) is a logically isolated section of the AWS cloud where you can launch AWS resources in a virtual network that you define. It allows you to control your network configuration, including IP address ranges, subnets, route tables, and network gateways.

Key Features Of VPC:

  • Isolation: Your VPC is isolated from other VPCs in the AWS cloud. -** Control:** You can define your IP address range, create subnets, and configure route tables.
  • Security: You can use security groups and network access control lists (ACLs) to control inbound and outbound traffic.

What is a Subnet?

A subnet is a segment of a VPC's IP address range where you can place AWS resources. Subnets help you organize and isolate resources within a VPC.

Types of Subnets:

  1. Public Subnet: A subnet that is connected to the internet. Resources in this subnet can communicate with the internet.
  2. Private Subnet: A subnet that is not directly connected to the internet. Resources in this subnet cannot access the internet directly.

Subnet CIDR Block:

Each subnet is defined by a CIDR (Classless Inter-Domain Routing) block, which specifies the IP address range for the subnet. For example, 10.0.1.0/24 defines a subnet with IP addresses ranging from 10.0.1.0 to 10.0.1.255.

What is an Internet Gateway?

An Internet Gateway (IGW) is a gateway attached to your VPC that enables communication between resources in your VPC and the internet. It acts as a bridge between your VPC and the internet, allowing resources with public IP addresses to communicate with external networks.

Key Points about Internet Gateways:

  • One IGW per VPC: You can attach only one IGW to a VPC.
  • Two-Way Communication: It allows both inbound and outbound traffic between your VPC and the internet.
  • No NAT Required: Unlike private subnets, resources in a public subnet can communicate directly with the internet using the IGW.

How to Make a Subnet Public or Private

Public Subnet:

  • Attach an Internet Gateway: Create and attach an IGW to your VPC.
  • Update Route Table: Configure the route table associated with the subnet to route traffic destined for the internet (0.0.0.0/0) to the IGW.

Private Subnet:

  • No Internet Gateway Required: Private subnets do not need an IGW.
  • NAT Gateway/Instance (Optional): If you need instances in a private subnet to access the internet, you can use a NAT Gateway or NAT Instance in a public subnet.

What is a Route Table?

A Route Table contains a set of rules (routes) that determine where network traffic is directed. It helps in routing traffic between subnets within a VPC and between the VPC and the internet.

Key Components of a Route Table:

  • Routes: Each route specifies a destination CIDR block and the target (e.g., IGW, NAT Gateway).
  • Main Route Table: By default, every VPC has a main route table that applies to all subnets unless overridden.
  • Custom Route Tables: You can create additional route tables and associate them with specific subnets.

Example Route Table Entries:

1. For Public Subnet:

  • Destination: 0.0.0.0/0
  • Target: IGW-ID

2. For Private Subnet:

  • Destination: 0.0.0.0/0
  • Target: NAT-Gateway-ID (if using NAT)

Summary:

In AWS, a VPC provides a secure and isolated virtual network for your resources. Subnets within a VPC can be classified as public or private based on their connectivity to the internet. An Internet Gateway enables communication between resources in public subnets and the internet. Route Tables manage how traffic is routed between subnets and external networks. Understanding and configuring these components properly helps you design a robust and secure network architecture in the cloud.

Top comments (0)