In modern cloud architecture, security is not an afterthought but a foundational layer. The core principle of defense-in-depth relies heavily on the separation of network traffic into public and private zones. This guide provides a concrete, hands-on lab scenario designed for IT students and junior engineers to build a secure Amazon Virtual Private Cloud (VPC). By configuring public subnets for internet-facing resources like NAT gateways and private subnets for application servers, you will learn how to implement critical network segmentation. We will also cover the creation of Network Access Control Lists (NACLs) to enforce stateless security rules at the subnet boundary, complementing Security Groups which operate at the instance level.
Understanding the Lab Architecture and Prerequisites
Before executing any commands or using the AWS Management Console, it is essential to understand the traffic flow and the specific components involved. In this scenario, we assume a standard AWS environment where you have an active account with sufficient credits or billing enabled. The goal is to deploy a web server that resides in a private subnet but can still serve content to the public internet via a NAT Gateway located in a public subnet.
Key Components:
* VPC: The virtual network containing your resources.
* Public Subnet: A subnet with a route to an Internet Gateway (IGW). This is where we place the NAT Gateway and Bastion hosts.
* Private Subnet: A subnet with no direct route to the internet, relying on the NAT Gateway for outbound connectivity.
* NAT Gateway: Allows instances in private subnets to initiate outbound connections while preventing inbound connections from the internet.
* Network ACL (NACL): Stateless firewalls that control traffic in and out of subnets. They operate at Layer 3 (IP) and are applied to subnets, unlike Security Groups which are stateful and attached to instances.
Prerequisites:
1. AWS Account access with Administrator or Programmatic Access roles.
2. Basic familiarity with the AWS Console navigation.
3. An understanding of CIDR notation (e.g., 10.0.0.0/16).
Step 1: Create the VPC and Define Subnets
The first actionable step is to establish the network foundation. Navigate to the VPC Dashboard in the AWS Console. Click “Create VPC” and enter a CIDR block, such as 10.0.0.0/16. This provides a large address space for growth. Once created, you must define subnets within this VPC.
To create the public subnet, click “Subnets” in the left navigation menu and select “Create subnet.” Enter a name like Public-Subnet-US-East and choose an Availability Zone. For the CIDR block, use a specific range, for example, 10.0.1.0/24. Repeat this process to create a private subnet with a non-overlapping range, such as 10.0.2.0/24, in a different Availability Zone for high availability.
Expected Result:
You will see two subnets listed under your VPC. The public subnet should be associated with the VPC but not yet linked to an Internet Gateway. The private subnet exists solely within the VPC context.
Step 2: Configure Routing Tables and Attach the NAT Gateway
A secure VPC requires precise routing. By default, subnets have no internet access. You must modify the route tables. First, attach an Internet Gateway (IGW) to your VPC by navigating to “Internet Gateways,” creating one, and selecting your VPC from the dropdown. This allows traffic to flow between the internet and the public subnet.
Next, create a NAT Gateway. Go to “NAT Gateways” and click “Create NAT Gateway.” Select an existing public subnet (created in Step 1) as the Subnet for the NAT Gateway. Choose a fixed Elastic IP address; this is crucial so that the NAT endpoint remains consistent even if the underlying infrastructure changes. During creation, specify the private subnets you want to associate with the NAT Gateway.
Crucial Routing Logic:
Navigate to “Route Tables.” Select the route table associated with your Private Subnet. Click “Edit routes” and add a new route. Set the Destination to 0.0.0.0/0 (all traffic) and the Target to the ID of your newly created NAT Gateway. Do not modify the Public Subnet’s route table; it should retain its default route pointing directly to the Internet Gateway.
Step 3: Implement Network Access Control Lists (NACLs)
While Security Groups protect instances, NACLs provide an additional layer of protection by filtering traffic at the subnet level. This is a best practice for preventing lateral movement if an instance is compromised. Navigate to “Network ACLs” and create a new one named Secure-Private-NACL.
Configure the rules carefully:
1. Inbound Rule: Allow all traffic from your NAT Gateway’s Elastic IP (or allow specific ports like 80/443 if you are testing web access). Deny all other inbound traffic by default.
2. Outbound Rule: Allow all outbound traffic to the internet (0.0.0.0/0) on port 80, 443, and 53 (DNS), but restrict others as needed for compliance.
Associate this new NACL with your Private Subnet. Leave the Public Subnet with its default “Allow All” NACL or configure it strictly to allow return traffic from the NAT Gateway. Remember that NACLs are stateless; if you block inbound traffic, you must explicitly allow the corresponding outbound response traffic in a separate rule.
Verification and Common Errors
After completing these steps, verify your configuration. Launch an EC2 instance (e.g., Amazon Linux or Ubuntu) in the private subnet with a public IP disabled. Attempt to ping google.com from the instance. If successful, the NAT Gateway routing is correct. If you attempt to initiate an inbound connection from the internet directly to this instance, it should fail, confirming your NACL and Security Group restrictions are working.
Common Errors and Fixes:
* Error: “No route to host” when trying to reach the internet from a private subnet.
* Fix: Check the Private Subnet’s Route Table. Ensure there is a route 0.0.0.0/0 pointing to the NAT Gateway ID, not the Internet Gateway.
* Error: Instance cannot receive responses from external requests even with NACLs configured.
* Fix: Remember that NACLs are stateless. You may have blocked the inbound request but failed to allow the specific outbound response port in a different rule. Ensure your outbound rules are permissive enough for return traffic.
* Error: NAT Gateway fails to launch.
* Fix: Verify that the chosen subnet has an associated Internet Gateway and is marked as public. The subnet must have a route to the IGW for the NAT Gateway itself to function.
Industry Application and Cost Controls
In a real-world enterprise scenario, this architecture supports critical workloads like databases running in private subnets that must be accessible only by application servers in other private subnets or via a bastion host. This segmentation reduces the attack surface significantly.
Cost control is also vital in AWS labs and production. NAT Gateways incur hourly charges plus data processing fees. To manage costs, monitor your usage in the Cost Explorer. If you are in a lab environment, consider deleting the NAT Gateway when not in use, though this will break internet access for private instances. Always ensure you release Elastic IPs associated with NAT Gateways or security groups to prevent orphaned resource charges.
Student Practice Task
To solidify your understanding, attempt this task: Create a VPC with two subnets. Launch an EC2 instance in the public subnet and another in the private subnet. Configure the route table so the private instance can reach the public one. Then, modify the NACL of the private subnet to block inbound traffic from the public subnet entirely (except for specific management ports). Observe how this change isolates the application layer while maintaining necessary connectivity patterns. This exercise mirrors real-world micro-segmentation strategies used in financial and healthcare sectors where data privacy is paramount.
Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.

