Understanding Key Networking Concepts
Before diving into subnet calculations and setting up a VPC on AWS, it’s crucial to understand the foundational concepts.
1. What is an IP Address?
An IP (Internet Protocol) address is a unique numerical label assigned to devices connected to a network. It identifies both the network and the device on that network. For example, 192.168.1.1
is a private IP address often used in home networks.
IP addresses come in two versions:
-
IPv4: A 32-bit address system, e.g.,
192.168.1.1
. It supports approximately 4.3 billion addresses. -
IPv6: A 128-bit address system, e.g.,
2001:0db8:85a3::8a2e:0370:7334
. It provides a much larger address space.
2. What is a VPC?
A VPC (Virtual Private Cloud) is a logically isolated network within a cloud environment. In AWS, a VPC allows you to launch resources such as EC2 instances in a secure network. You define your VPC’s IP range using a CIDR block.
After Creating VPC
3. What is CIDR?
CIDR (Classless Inter-Domain Routing) is a method for allocating IP addresses and efficiently managing IP networks. CIDR blocks are written in the format IP/Prefix
, where the prefix determines the network size.
For example:
-
192.168.1.0/24
: The/24
means the first 24 bits are reserved for the network, leaving 8 bits for hosts. This gives 256 total IPs (254 usable, excluding network and broadcast addresses).
Prefix | Total IPs | Usable IPs |
---|---|---|
/16 | 65,536 | 65,534 |
/24 | 256 | 254 |
/25 | 128 | 126 |
/26 | 64 | 62 |
/27 | 32 | 30 |
Check end of page to see sample of my calculation I did.
4. What is Subnetting?
Subnetting divides a larger network into smaller, isolated networks (subnets). Each subnet has its own range of IP addresses, allowing better organization and security.
For example, a VPC with a CIDR block of 172.16.0.0/24
can be divided into smaller subnets:
- Subnet 1:
172.16.0.0/25
(128 IPs) - Subnet 2:
172.16.0.128/26
(64 IPs) - Subnet 3:
172.16.0.192/27
(32 IPs)
5. Reserved IP Addresses
AWS reserves 5 IP addresses in every subnet:
- Network Address: The first IP in the range.
- Gateway Address: The second IP, used as the default gateway.
- DNS Reserved: The third IP, for AWS DNS.
- Future Use: The fourth IP.
- Broadcast Address: The last IP in the range.
Calculating Subnet Ranges
Step-by-Step Subnet Calculation
Let’s say you have a VPC with a CIDR block of 172.16.0.0/24
, and you need the following subnets:
- Subnet 1: 80 IPs
- Subnet 2: 50 IPs
- Subnet 3: 20 IPs
Step 1: Determine Subnet Sizes
Each subnet must be sized to the nearest power of 2 that accommodates the required IPs:
- Subnet 1: Requires 80 IPs → Nearest power of 2 = 128 IPs → CIDR =
/25
. - Subnet 2: Requires 50 IPs → Nearest power of 2 = 64 IPs → CIDR =
/26
. - Subnet 3: Requires 20 IPs → Nearest power of 2 = 32 IPs → CIDR =
/27
.
Step 2: Allocate Non-Overlapping Ranges
Start each subnet at the next available boundary:
- Subnet 1:
172.16.0.0/25
→ IP Range:172.16.0.0 - 172.16.0.127
- Subnet 2:
172.16.0.128/26
→ IP Range:172.16.0.128 - 172.16.0.191
- Subnet 3:
172.16.0.192/27
→ IP Range:172.16.0.192 - 172.16.0.223
Subnet 1
Subnet 2
Subnet 3
Setting Up a VPC on AWS
Step 1: Create a VPC
- Log in to the AWS Management Console.
- Go to VPC > Create VPC.
- Enter the following details:
-
Name:
MyVPC
-
IPv4 CIDR block:
172.16.0.0/24
-
Name:
- Click Create VPC.
Step 2: Create Subnets
- Navigate to Subnets > Create Subnet.
- For Subnet 1:
-
Name:
Subnet1
-
VPC: Select
MyVPC
. -
CIDR Block:
172.16.0.0/25
-
Name:
- Repeat for Subnet 2 (
172.16.0.128/26
) and Subnet 3 (172.16.0.192/27
).
This is the outcome after successfully creating the VPC, CIDR, and Subnet.
Step 3: Create an Internet Gateway
- Go to Internet Gateways > Create Internet Gateway.
- Attach the Internet Gateway to
MyVPC
.
Step 4: Update Route Tables
- Go to Route Tables and find the route table associated with
MyVPC
. - Add a route:
-
Destination:
0.0.0.0/0
- Target: Select the Internet Gateway.
-
Destination:
- Associate the route table with your subnets.
Step 5: Launch an EC2 Instance
- Navigate to EC2 > Launch Instance.
- Select an Amazon Machine Image (AMI).
- Choose an instance type (e.g., t2.micro).
- Place the instance in one of your subnets (e.g.,
Subnet1
). - Assign a public IP to enable internet access.
Here is my calculation, and you can use it as a reference or formula.
Conclusion
Subnetting and setting up a VPC may seem intimidating at first, but with a solid understanding of CIDR and IP address allocation, it becomes straightforward. Following the steps above ensures your AWS network is organized, secure, and scalable.
Feel free to share your thoughts or ask questions in the comments below!
Top comments (0)