AWS VPC Networking: Complete Guide

x32x01
  • by x32x01 ||
AWS VPC Networking: Complete Guide
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.

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
This provides 16,384 total IPv4 addresses.
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
💡 Important: AWS reserves five IPv4 addresses in every subnet, so not all 4,096 addresses are available for your resources.



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.
For our architecture, we'll use two Availability Zones and create two subnets in each:
Availability ZoneSubnetType
AZ-A10.0.0.0/20Public
AZ-A10.0.16.0/20Private
AZ-B10.0.32.0/20Public
AZ-B10.0.48.0/20Private
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.



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
This tells AWS to send IPv4 traffic destined for external networks through the 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.
One important detail: an EC2 instance in a public subnet also needs a public IPv4 address or Elastic IP, along with appropriate security rules, to communicate directly with the internet.



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:
  1. Create a NAT Gateway inside a public subnet.
  2. Associate an Elastic IP address with it.
  3. Ensure the public subnet has a route to the Internet Gateway.
  4. Update the private subnet's route table.
The private route table should contain:
Code:
Destination: 0.0.0.0/0
Target: NAT Gateway
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.



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
The Bastion Host needs network connectivity to the private instance, and its Security Group must allow SSH access from the authorized source.
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.
For production environments, consider AWS Systems Manager Session Manager. It provides managed access to EC2 instances without requiring an internet-facing SSH port or a traditional Bastion Host.



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.
2. Network Access Control Lists (NACLs)
  • 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.
Here's a quick comparison:
FeatureSecurity GroupNetwork ACL
ScopeNetwork interfaceSubnet
TypeStatefulStateless
Allow rulesYesYes
Deny rulesNoYes
Applied toResourcesSubnets
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.



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
Additional components:
  • 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.
The architecture should also include appropriate Security Groups, Network ACLs, and route tables.



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.
These are some of the most important concepts to understand before designing or managing an AWS VPC architecture.
 
Similar threads
x32x01
Replies
0
Views
240
x32x01
x32x01
x32x01
Replies
0
Views
214
x32x01
x32x01
x32x01
Replies
0
Views
246
x32x01
x32x01
x32x01
Replies
0
Views
301
x32x01
x32x01
Register & Login Faster
Forgot your password?
Forum Statistics
Threads
1,283
Messages
1,291
Members
22
Latest Member
elparqetcom
Back
Top