What if a simple network setup could protect your data and keep your app running smoothly without headaches?
Public vs private subnets in AWS - When to Use Which
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine setting up a network for your app where some parts need to be open to the internet, and others must stay hidden for security. Doing this by hand means manually configuring each server's access and firewall rules, which can get confusing fast.
Manually managing which servers can talk to the internet or stay private is slow and risky. One wrong setting can expose sensitive data or block important traffic, causing downtime or security breaches.
Using public and private subnets lets you organize your network clearly: public subnets for internet-facing resources, private subnets for secure internal ones. This setup automates access control and keeps your system safe and reliable.
Set firewall rules on each server manually to allow or block internet access.Create public and private subnets; assign servers accordingly; routing and security are handled automatically.
This approach makes it easy to build secure, scalable networks where sensitive parts stay protected while public parts stay reachable.
A web app uses a public subnet for its web servers so users can connect, and a private subnet for its database servers to keep data safe from outside access.
Manual network setup is complex and error-prone.
Public and private subnets organize resources by access needs.
This improves security and simplifies management.
Practice
Solution
Step 1: Understand public subnet characteristics
A public subnet allows resources to communicate directly with the internet by assigning public IP addresses.Step 2: Compare with other subnet types
Private subnets do not assign public IPs and restrict internet access, unlike public subnets.Final Answer:
It has direct internet access and assigns public IPs automatically. -> Option AQuick Check:
Public subnet = direct internet access [OK]
- Confusing private subnet with public subnet
- Thinking all subnets have internet access
- Assuming VPN is needed for public subnet
Solution
Step 1: Identify private subnet IP assignment
Private subnets do not assign public IPs automatically, soMapPublicIpOnLaunchmust be false.Step 2: Understand routing and gateway settings
Internet Gateway (IGW) and routing to 0.0.0.0/0 are for public subnets, not private.Final Answer:
<code>MapPublicIpOnLaunch: false</code> -> Option CQuick Check:
Private subnet = no public IP assignment [OK]
- Setting public IP assignment to true for private subnet
- Confusing internet gateway with subnet config
- Using public route table for private subnet
Destination: 0.0.0.0/0, Target: igw-12345What type of subnet is this likely to be?
Solution
Step 1: Analyze route table destination and target
The route directs all internet traffic (0.0.0.0/0) to an internet gateway (igw), which enables internet access.Step 2: Determine subnet type from routing
Routing to an internet gateway means the subnet is public and can access the internet directly.Final Answer:
Public subnet with internet access -> Option AQuick Check:
Route to IGW = public subnet [OK]
- Assuming NAT gateway means public subnet
- Confusing IGW with VPN or NAT
- Ignoring route table targets
MapPublicIpOnLaunch: false but instances still get public IPs. What is the likely issue?Solution
Step 1: Understand subnet vs instance IP assignment
Subnet setting disables automatic public IP assignment, but instance launch settings can override this.Step 2: Identify cause of public IP despite subnet config
If instance launch config explicitly assigns public IPs, it overrides subnet default behavior.Final Answer:
The instance launch configuration overrides subnet settings to assign public IPs. -> Option BQuick Check:
Instance config can override subnet IP assignment [OK]
- Blaming route table for IP assignment
- Ignoring instance-level settings
- Confusing CIDR overlap with IP assignment
Solution
Step 1: Identify subnet roles for internet access
The web server needs internet access, so it belongs in a public subnet with a route to the internet gateway.Step 2: Secure the database internally
The database should be in a private subnet without direct internet access to keep it secure.Final Answer:
Place the web server in a public subnet and the database in a private subnet. -> Option DQuick Check:
Internet-facing resources in public, internal in private [OK]
- Putting database in public subnet
- Putting web server in private subnet
- Relying only on security groups without subnet design
