- by x32x01 ||
Understanding AWS VPC networking is essential when moving applications from on-premises infrastructure to the cloud. You need to know how to divide IP ranges, configure public and private subnets, control internet access, and secure private resources.
This practical guide walks through a typical AWS network architecture, from creating a VPC to deploying applications across multiple Availability Zones.
A VPC is a logically isolated virtual network in AWS where you can deploy resources such as EC2 instances, databases, and load balancers.
Let's assume a company wants to migrate its on-premises infrastructure to AWS.
The network architect creates a VPC with this CIDR block:
This provides 16,384 total IPv4 addresses.
The requirement is to divide the VPC into four equal-sized subnets.
Each subnet will use a
The resulting subnets are:
💡 Important: AWS reserves five IPv4 addresses in every subnet, so not all 4,096 addresses are available for your resources.
Why use two Availability Zones?
To achieve High Availability and Fault Isolation.
If one Availability Zone experiences an outage, resources in the other AZ can continue serving traffic, assuming the application is designed for redundancy.
⚠️ Never use overlapping CIDR ranges between subnets in the same VPC. Overlapping IP ranges create addressing and routing problems.
After creating the VPC, attach an Internet Gateway to it.
Next, configure the route table associated with your public subnets.
Add this route:
This tells AWS to send IPv4 traffic destined for external networks through the Internet Gateway.
This is where the NAT Gateway comes in.
A public NAT Gateway allows resources in private subnets to initiate outbound connections to the internet without exposing those resources to unsolicited inbound internet connections.
The architecture works as follows:
Now, a private EC2 instance can access external services through the NAT Gateway.
For example, an application server can download software updates without needing a public IP address.
💡 Production tip: For high availability, deploy a NAT Gateway in each Availability Zone and route private subnet traffic through the NAT Gateway in the same AZ. This avoids making internet access dependent on a single AZ.
You can use a Bastion Host.
A Bastion Host is an EC2 instance deployed in a public subnet that acts as a controlled entry point to private infrastructure.
The connection looks like this:
The Bastion Host needs network connectivity to the private instance, and its Security Group must allow SSH access from the authorized source.
Security recommendations:
1. Security Groups
For example, when launching an EC2 instance, you associate it with a Security Group.
A subnet, meanwhile, is associated with a Network ACL. Every subnet must have one, and AWS automatically associates new subnets with the VPC's default NACL unless you configure another one.
A typical web application might look like this:
Additional components:
The key concepts to remember are:
This practical guide walks through a typical AWS network architecture, from creating a VPC to deploying applications across multiple Availability Zones.
1. Creating a VPC and Dividing the IP Range
The first step is to create an Amazon VPC (Virtual Private Cloud).A VPC is a logically isolated virtual network in AWS where you can deploy resources such as EC2 instances, databases, and load balancers.
Let's assume a company wants to migrate its on-premises infrastructure to AWS.
The network architect creates a VPC with this CIDR block:
Code:
10.0.0.0/18 The requirement is to divide the VPC into four equal-sized subnets.
Each subnet will use a
/20 CIDR block, providing 4,096 addresses.The resulting subnets are:
Code:
10.0.0.0/20
10.0.16.0/20
10.0.32.0/20
10.0.48.0/20 2. Regions and Availability Zones
AWS infrastructure is organized into:- Region: A geographical area containing multiple Availability Zones.
- Availability Zone (AZ): An isolated location within a Region consisting of one or more data centers.
- Subnet: A network segment that exists entirely within one Availability Zone.
| Availability Zone | Subnet | Type |
|---|---|---|
| AZ-A | 10.0.0.0/20 | Public |
| AZ-A | 10.0.16.0/20 | Private |
| AZ-B | 10.0.32.0/20 | Public |
| AZ-B | 10.0.48.0/20 | Private |
To achieve High Availability and Fault Isolation.
If one Availability Zone experiences an outage, resources in the other AZ can continue serving traffic, assuming the application is designed for redundancy.
⚠️ Never use overlapping CIDR ranges between subnets in the same VPC. Overlapping IP ranges create addressing and routing problems.
3. Internet Gateway (IGW)
An Internet Gateway (IGW) allows communication between resources in your VPC and the public internet.After creating the VPC, attach an Internet Gateway to it.
Next, configure the route table associated with your public subnets.
Add this route:
Code:
Destination: 0.0.0.0/0
Target: Internet Gateway Public vs. Private Subnets
The main difference is their routing configuration:- Public Subnet: Has a direct route to an Internet Gateway.
- Private Subnet: Does not have a direct route to an Internet Gateway.
4. NAT Gateway
What if an EC2 instance is running in a private subnet but needs internet access to download updates or connect to external services?This is where the NAT Gateway comes in.
A public NAT Gateway allows resources in private subnets to initiate outbound connections to the internet without exposing those resources to unsolicited inbound internet connections.
The architecture works as follows:
- Create a NAT Gateway inside a public subnet.
- Associate an Elastic IP address with it.
- Ensure the public subnet has a route to the Internet Gateway.
- Update the private subnet's route table.
Code:
Destination: 0.0.0.0/0
Target: NAT Gateway For example, an application server can download software updates without needing a public IP address.
💡 Production tip: For high availability, deploy a NAT Gateway in each Availability Zone and route private subnet traffic through the NAT Gateway in the same AZ. This avoids making internet access dependent on a single AZ.
5. Bastion Host and Secure Access
Suppose you have an EC2 instance in a private subnet and need to connect to it using SSH.You can use a Bastion Host.
A Bastion Host is an EC2 instance deployed in a public subnet that acts as a controlled entry point to private infrastructure.
The connection looks like this:
Code:
Your Computer
|
| SSH (Port 22)
v
Bastion Host (Public Subnet)
|
| SSH
v
Private EC2 Instance Security recommendations:
- Never expose SSH port 22 to the entire internet unless absolutely necessary.
- Restrict access to trusted IP addresses.
- Allow SSH from the Bastion Host's Security Group to the private instance.
- Keep the Bastion Host updated.
6. Security Groups vs. Network ACLs
AWS provides two important network security mechanisms:1. Security Groups
- Operate at the resource's network interface level.
- Control inbound and outbound traffic.
- Are Stateful.
- Support Allow rules only.
- Automatically allow response traffic for permitted connections.
- Operate at the subnet level.
- Control inbound and outbound traffic.
- Are Stateless.
- Support both Allow and Deny rules.
- Require separate rules for inbound and outbound traffic, including response traffic.
| Feature | Security Group | Network ACL |
|---|---|---|
| Scope | Network interface | Subnet |
| Type | Stateful | Stateless |
| Allow rules | Yes | Yes |
| Deny rules | No | Yes |
| Applied to | Resources | Subnets |
A subnet, meanwhile, is associated with a Network ACL. Every subnet must have one, and AWS automatically associates new subnets with the VPC's default NACL unless you configure another one.
7. Putting Everything Together: Production Architecture
Now let's combine these components into a simple production architecture.A typical web application might look like this:
Code:
Internet
|
v
Route 53
|
v
Application Load Balancer
|
+----------+----------+
| |
v v
AZ-A AZ-B
Private EC2 Private EC2
| |
+----------+----------+
|
v
RDS Multi-AZ - Route 53: AWS DNS service that routes users to your application using DNS records.
- Application Load Balancer: Distributes incoming application traffic across EC2 instances in multiple Availability Zones.
- Private EC2 Instances: Run the application without direct public internet exposure.
- RDS Multi-AZ: Provides database availability through a standby DB instance in another Availability Zone.
- NAT Gateway: Provides outbound internet access for private resources when needed.
Final Thoughts
Understanding these AWS networking components gives you a solid foundation for designing secure and highly available cloud infrastructure.The key concepts to remember are:
- VPC: Your isolated virtual network.
- Subnets: Divide your network into smaller segments.
- Availability Zones: Help achieve high availability.
- Internet Gateway: Provides direct internet connectivity.
- NAT Gateway: Allows private resources to initiate outbound internet connections.
- Bastion Host: Provides controlled administrative access.
- Security Groups and NACLs: Protect your network at different levels.