AWS Networking
Learn how AWS networking works. VPC, Subnets, Security Groups, and more explained in simple terms.
What is VPC?
VPC (Virtual Private Cloud) is your private network in AWS. Think of it as your own personal data center in the cloud.
VPC Components Explained
| Component | Description | Analogy |
|---|---|---|
| VPC | Your private network | A house |
| Subnet | A section of your VPC | Rooms in the house |
| Internet Gateway | Connects VPC to internet | Front door |
| Route Table | Controls traffic routing | House map |
| Security Group | Firewall for instances | Room locks |
| NACL | Firewall for subnets | House security system |
Subnets - Dividing Your VPC
A Subnet is a range of IP addresses in your VPC. You divide your VPC into subnets to organize resources.
Public Subnet
Has internet access via Internet Gateway. Used for web servers, load balancers.
Private Subnet
No direct internet access. Used for databases, application servers.
Security Groups - Your First Line of Defense
A Security Group acts as a virtual firewall for your EC2 instances. It controls inbound and outbound traffic.
Inbound Rules
Controls what traffic can enter your instance.
Example: Allow SSH (port 22) from your IP
Outbound Rules
Controls what traffic can leave your instance.
Example: Allow all outbound traffic
Exercise: Create a VPC
Task: Create a VPC with public and private subnets.
- Create a VPC with CIDR block
10.0.0.0/16 - Create 2 public subnets (10.0.1.0/24, 10.0.2.0/24)
- Create 2 private subnets (10.0.3.0/24, 10.0.4.0/24)
- Create an Internet Gateway and attach it
- Create a route table and associate with public subnets
- Launch an EC2 instance in a public subnet
- Connect to it and verify internet access
Show Solution
# 1. Create VPC
aws ec2 create-vpc --cidr-block 10.0.0.0/16
# 2. Create Subnets
aws ec2 create-subnet --vpc-id vpc-xxx --cidr-block 10.0.1.0/24 --availability-zone us-east-1a
aws ec2 create-subnet --vpc-id vpc-xxx --cidr-block 10.0.2.0/24 --availability-zone us-east-1b
aws ec2 create-subnet --vpc-id vpc-xxx --cidr-block 10.0.3.0/24 --availability-zone us-east-1a
aws ec2 create-subnet --vpc-id vpc-xxx --cidr-block 10.0.4.0/24 --availability-zone us-east-1b
# 3. Create and attach Internet Gateway
aws ec2 create-internet-gateway
aws ec2 attach-internet-gateway --internet-gateway-id igw-xxx --vpc-id vpc-xxx
# 4. Create route table for public subnets
aws ec2 create-route-table --vpc-id vpc-xxx
aws ec2 create-route --route-table-id rtb-xxx --destination-cidr-block 0.0.0.0/0 --gateway-id igw-xxx
aws ec2 associate-route-table --route-table-id rtb-xxx --subnet-id subnet-xxx
Key Takeaway
VPC is your private network in AWS. Use public subnets for resources that need internet access and private subnets for internal resources. Security Groups are your first line of defense for EC2 instances.