This lesson combines 3 topics: VPC Fundamentals, Subnets and Routing, Security Groups and NACLs.
Learning Objectives
- Understand VPC architecture and CIDR blocks
- Distinguish Public vs Private subnets
- Know Internet Gateway, NAT Gateway, NAT Instance
- Understand IPv4 and IPv6 in a VPC
- Understand how to design a sensible subnet layout
- Know advanced Route Tables (multiple targets, propagation)
- Distinguish VPC Peering and Transit Gateway
- Understand CIDR planning best practices
- Understand the difference between SG and NACL
- Know Stateful vs Stateless behavior
- Know when to use SG vs NACL
- Understand Flow Logs for network debugging
Part 1: VPC Fundamentals
1. VPC Overview
VPC (Virtual Private Cloud) = an isolated virtual network inside an AWS Region, where you have full control over:
- IP address range (CIDR)
- Subnets (per AZ)
- Route tables
- Network gateways (IGW, NAT, VPN, Transit Gateway)
- Security: Security Groups, NACLs, Flow Logs
Characteristics
- Region-scoped: a VPC lives in 1 Region and spans all AZs of that Region
- Default VPC is created automatically in each Region when the account is opened (1 subnet/AZ, IGW attached)
- Custom VPC: you design the architecture yourself
- Default quota: 5 VPCs/Region (can be increased)
2. CIDR Block
IPv4 CIDR
- Allowed range: /16 (65,536 IPs) to /28 (16 IPs)
- Private IP ranges (RFC 1918 — recommended):
10.0.0.0/8(16M IPs)172.16.0.0/12(1M IPs)192.168.0.0/16(65k IPs)
- No overlap with other VPCs if you need peering/Transit Gateway
Example
Secondary CIDR Blocks
- You can add secondary IPv4 CIDRs (up to 5 blocks per VPC)
- Used to expand when you run out of IPs
- Must not overlap with the primary CIDR or with other VPCs
IPv6 CIDR
- AWS-assigned /56 from Amazon's pool
- Or bring your own (BYOIP)
- Each IPv6 subnet uses a /64
- IPv6 is always public (there is no private IPv6 in AWS)
3. Subnet
Definition
Subnet = a subdivision of the VPC CIDR; each subnet belongs to 1 AZ.
Reserved IPs (5 IPs/subnet)
Subnet: 10.0.1.0/24 (256 IPs, 251 usable)
10.0.1.0 - Network address
10.0.1.1 - VPC Router
10.0.1.2 - DNS Server (.2 of the VPC CIDR)
10.0.1.3 - Reserved (future use)
10.0.1.255 - Broadcast (not used in a VPC)
Subnet types
| Type | Route to internet | Use case |
|---|---|---|
| Public | Direct via IGW | Web servers, ALB, NAT GW |
| Private | Via NAT GW (egress only) | DB, app servers |
| Isolated | No internet | Air-gapped, compliance |
Public Subnet conditions
- Route 0.0.0.0/0 → Internet Gateway in the route table
- The instance has a Public IP or Elastic IP
- (Auto-assign Public IPv4 enabled for the subnet — optional)
4. Internet Gateway (IGW)
Characteristics
- Horizontally scaled, redundant, highly available (no HA concerns)
- 1 IGW per VPC (only 1)
- No bandwidth limit
- Free (you only pay normal data transfer)
Workflow
Setup
- Create IGW
- Attach to VPC
- Add route
0.0.0.0/0 → igw-xxxin the route table - Associate the subnet with this route table
- Launched instance has a Public IP
5. NAT Gateway
Definition
NAT Gateway = a managed service that lets private subnet instances initiate connections out to the internet (egress) while NOT allowing inbound connections from the internet.
Characteristics
- Managed by AWS (no maintenance)
- High availability within 1 AZ (placed in 1 AZ)
- Bandwidth scales automatically up to 100 Gbps
- Requires an Elastic IP
- Placed in a public subnet; routes from private subnets point to the NAT GW
Cost
- $0.045/hour (us-east-1, ~$32/month)
- $0.045/GB data processed
- Expensive → consider VPC Endpoints to reduce it
Multi-AZ NAT
Best practice: 1 NAT GW per AZ to avoid a single point of failure and avoid cross-AZ traffic charges.
6. NAT Instance (Legacy)
Characteristics
- An EC2 instance running NAT software (Linux)
- You must manage it yourself (patching, scaling, HA)
- Disable Source/Dest check on the ENI
- Bandwidth depends on the instance type
- Can double as a bastion host (NAT GW cannot)
- Has a Security Group (NAT GW does not)
Comparison
| Feature | NAT Gateway | NAT Instance |
|---|---|---|
| Availability | HA within AZ | Self-managed |
| Bandwidth | Up to 100 Gbps | Depends on instance |
| Maintenance | AWS-managed | Self-managed |
| Security Group | No (NACL only) | Yes |
| Bastion role | No | Possible |
| Cost | $0.045/hr + $/GB | EC2 cost only |
Recommendation: Use NAT Gateway unless you have a specific reason (very low cost + dual-purpose bastion).
7. Egress-Only Internet Gateway (IPv6)
Definition
The equivalent of a NAT Gateway but for IPv6 (because IPv6 has no concept of "private").
Characteristics
- Stateful, only allows outbound IPv6 initiation
- Inbound blocked (egress-only)
- Free
- Use case: IPv6 private subnet instances that need outbound internet
8. Route Tables
Structure
Route Priority
- Longest Prefix Match (most specific wins)
10.0.1.0/24takes priority over10.0.0.0/16- The local route always has the highest priority
Targets
| Target | Description |
|---|---|
local | Traffic within the VPC CIDR |
igw-xxx | Internet Gateway |
nat-xxx | NAT Gateway |
vgw-xxx | Virtual Private Gateway (VPN) |
tgw-xxx | Transit Gateway |
pcx-xxx | VPC Peering |
vpce-xxx | VPC Endpoint |
eigw-xxx | Egress-Only IGW (IPv6) |
eni-xxx | ENI (NAT Instance, firewall appliance) |
Main Route Table vs Custom
- Each VPC has 1 Main Route Table (default)
- A subnet not associated with a specific route table → uses the Main one
- Best practice: Create a custom route table for each subnet type (public, private)
9. Elastic IP (EIP)
Definition
EIP = a static public IPv4 address allocated to your account, which can be moved between instances.
Characteristics
- Fixed public IP (does not change on instance stop/start)
- Before 2/2024: free when attached to a running instance, only charged when idle
- Since 2/2024: every public IPv4 (including attached EIPs) is charged $0.005/hour — see §10
- Limit: 5 EIPs/account/Region (request an increase)
Use case
- NAT Gateway, NAT Instance
- A web server that needs a fixed IP
- Whitelisting with external services
Best practice
- Don't over-allocate EIPs (they cost money)
- Use DNS instead of an EIP when possible
- For web apps: use ALB/NLB (NLB gets a static IP per AZ automatically)
10. Public IPv4 (Pricing change 2024)
Important update (2024-02-01)
- AWS charges $0.005/hour for every public IPv4 address (including attached ones, including EC2 free tier)
- 1 IPv4 = $3.6/month
- Includes: EC2 public IP, Elastic IP, ELB public IP, NAT Gateway
Implication
- Higher cost for workloads with many public IPs
- Encourages IPv6 adoption, private subnets + NAT, CloudFront, VPC Endpoints
11. IPv6 in a VPC
Characteristics
- IPv6 is always public (no private IPv6)
- Each instance can have IPv6 + IPv4 (dual stack)
- Or be an IPv6-only instance (requires an IPv6-only subnet)
- Free (IPv6 is not charged like IPv4)
Setup
- Enable IPv6 on the VPC (assign a /56 from Amazon)
- Add a /64 IPv6 CIDR to the subnet
- Add route
::/0 → IGW(public) or::/0 → EIGW(private) - Enable IPv6 on the instance ENI
Use case
- New apps designed for IPv6 (mobile, IoT)
- Save cost compared to IPv4 (Feb 2024 pricing change)
- Future-proof
12. VPC Architecture Example
Pattern: 3-tier web application
Part 2: Subnets and Routing
1. Subnet Design Best Practices
Principles
- Separate subnets by function: public web, private app, private DB
- Each tier has its own subnet in each AZ (HA)
- At least 2 AZs for production
- Size subnets sensibly: not too large (wasteful), not too small (runs out early)
- Reserve space for growth
Sizing recommendation
| Use case | Suggested size |
|---|---|
| ELB/ALB subnet | /27 or /28 (needs few IPs) |
| Web tier | /24 (256 IPs) |
| App tier | /23 (512 IPs) |
| DB tier | /27 (32 IPs is enough) |
| EKS pod subnet | /20 or larger |
Example VPC sizing
2. Route Table Advanced
1 Route Table → many subnets
- 1 route table can be associated with many subnets
- But 1 subnet can only be associated with 1 route table at a time
Pattern: Public RT + Private RT
Route Propagation (for VPN/Direct Connect)
- A VGW (Virtual Private Gateway) can propagate routes from on-prem via BGP
- Routes are added to the route table automatically → instances can access on-prem subnets
3. VPC Peering
Definition
VPC Peering = a direct network connection between 2 VPCs.
Characteristics
- Same Region: regular VPC Peering
- Cross-region: also supported (Inter-Region VPC Peering)
- Cross-account: 2 different accounts also work
- CIDRs must not overlap
- NOT TRANSITIVE: A peers with B, B peers with C → A does NOT automatically reach C
- Update the route table in each VPC to route traffic through the peering
Limitations
- No transitive routing
- No support for overlapping CIDRs
- Mesh complexity (n^2 connections for n VPCs)
- Cross-VPC DNS resolution: must be enabled in the peering settings
Use case
- 2-3 VPCs that need to connect (simple)
- Cross-account (vendor sharing)
When to use Transit Gateway instead?
- >3 VPCs need to interconnect
- Transitive routing is required
- Hub-and-spoke pattern
- Easier management for enterprises
4. Transit Gateway (TGW) — Brief for SAA
Definition
TGW = a hub connecting many VPCs, VPNs, and Direct Connect in a single managed service.
Characteristics
- Hub-and-spoke: every VPC connects to the TGW, no peering between VPCs needed
- Transitive: A-TGW-B-TGW-C, A can reach C
- Cross-region support (TGW Peering)
- Supports 5,000 VPCs/TGW
- Bandwidth scales automatically
Architecture
Cost
- $/hour per TGW attachment (~$0.05/hour per VPC/VPN)
- $/GB data processed
SAA-C03 mostly asks "when to use TGW vs Peering". TGW details belong to SAP-C02.
5. VPC Endpoints (Brief — details in Week 2 Day 2, Part 1)
Definition
VPC Endpoint = a private connection from a VPC to AWS services without going over the internet.
2 types
- Gateway Endpoint: S3, DynamoDB (free)
- Interface Endpoint: most other services (ENI in a subnet, $/hour + $/GB)
Benefits
- Security: traffic does not go out to the internet
- Cost: reduces NAT Gateway data processing fees
- Performance: lower latency
6. CIDR Planning Best Practices
Avoid overlap
- Plan ahead: VPCs, VPNs, on-prem CIDRs
- Avoid RFC 1918 ranges already used on-prem
- Document in an IPAM tool
AWS IPAM (IP Address Manager)
- A service for centrally managing IP space for an organization
- Auto-allocates CIDRs for new VPCs (no conflicts)
- Tracks usage, alerts when near full
- Cross-account, cross-region
Reserved ranges
- AWS uses 169.254.x.x (link-local) for metadata
- Avoid: 169.254.0.0/16 in custom CIDRs
Future-proof
- Pick /16 for a VPC (enough for most workloads)
- Reserve /8 for the organization (multi-VPC, multi-region)
7. Subnet Sharing with AWS RAM
Definition
AWS RAM (Resource Access Manager) = share resources cross-account.
VPC Sharing
- Create subnets in the owner account
- Share with participant accounts via RAM
- Participants launch EC2/RDS/Lambda in the shared subnet
- A single VPC used by many accounts
Benefits
- Centralized networking management (1 team)
- Application teams focus on business logic
- Simplifies cross-account access
Architecture
8. VPC Peering Configuration
Steps
- Requester initiates the peering request
- Accepter accepts the request
- Update the route table in both VPCs
- Update the Security Group to allow traffic from the peer VPC CIDR
- (Optional) Enable DNS resolution across the peering
Example
Security Group reference across VPC peering
- Same Region: an SG can reference the SG ID of the peer VPC
- Cross-region: only reference via CIDR (no SG ID)
9. AWS Global Accelerator (Brief)
Definition
Global Accelerator = anycast IP routing over the AWS backbone, routing users to the nearest healthy endpoint.
Characteristics
- 2 static IPs (anycast) for a global app
- Routes over the AWS backbone (faster than the public internet)
- Health checks across regions
- Automatic region failover
Use case
- Multi-region active-active app
- Static IPs needed for whitelisting
- Reduce latency for global users
- Gaming, IoT
Compared with CloudFront
| CloudFront | Global Accelerator | |
|---|---|---|
| Use case | Static + dynamic content caching | Non-HTTP (TCP/UDP), low-latency routing |
| IP | DNS name (changing) | Static anycast IPs |
| Caching | Yes | No |
| Protocol | HTTP/HTTPS | TCP, UDP, HTTP |
10. Common Network Patterns
Pattern 1: Single VPC Multi-AZ
- Simple, 1 region
- 2-3 AZs
- 1 NAT GW per AZ
Pattern 2: Multi-VPC with Peering
- 2-3 VPCs (dev, staging, prod)
- Peering between selected VPCs
- Simple routing
Pattern 3: Multi-VPC with Transit Gateway
- 10+ VPCs
- Centralized hub TGW
- Optional: centralized egress (shared NAT GW)
Pattern 4: VPC Sharing (RAM)
- 1 VPC owner, many participant accounts
- Centralized networking team
Pattern 5: Multi-Region with TGW Peering
- A TGW in each region
- TGW Peering connects the regions
- DR + global app
11. Network Connectivity Comparison
| Option | Use case | Cost | Bandwidth |
|---|---|---|---|
| VPC Peering | 2-3 VPCs | Free (same region) | No limit |
| Transit Gateway | Multi-VPC hub | $$$ | 50 Gbps/attachment |
| VPN | On-prem hybrid (encrypted) | $ | ~1.25 Gbps/tunnel |
| Direct Connect | On-prem (dedicated) | $$$ | 1, 10, 100 Gbps |
| VPC Endpoint | VPC → AWS service | $-$$ | High |
| PrivateLink | VPC → 3rd party service | $-$$ | High |
Part 3: Security Groups and NACLs
1. Security Groups (SG)
Definition
Security Group = a virtual firewall at the instance/ENI level.
Characteristics
- Stateful: response traffic is automatically allowed
- Allow rules only (no Deny rules)
- Defaults:
- Inbound: deny all
- Outbound: allow all
- Applied to: ENIs (EC2, ALB, RDS, ElastiCache, Lambda in VPC...)
- Maximum 5 SGs/ENI
- Maximum 60 inbound + 60 outbound rules/SG
- Can reference another SG or a CIDR as source/destination
Rule Components
Reference SG (best practice)
SG-Web (web servers):
Inbound: HTTP/HTTPS from 0.0.0.0/0
Outbound: ALL to 0.0.0.0/0
SG-App (app servers):
Inbound: TCP 8080 from SG-Web ← reference!
Outbound: ALL
SG-DB (database):
Inbound: TCP 3306 from SG-App ← reference!
Outbound: ALL
→ When the ASG scales, you don't need to update CIDRs — just make sure instances are in the right SG.
Stateful behavior
Inbound rule: Allow port 80 from 0.0.0.0/0
↓
Request comes in → ALLOWED
Response goes out → AUTO-ALLOWED (no outbound rule needed for the ephemeral port)
2. Network ACLs (NACL)
Definition
NACL = a stateless firewall at the subnet level.
Characteristics
- Stateless: response traffic needs an explicit rule
- Allow AND Deny rules
- Applied to a subnet (1 NACL per subnet, 1 subnet has 1 NACL)
- The default NACL: allows all inbound + outbound
- Custom NACL: deny all by default
- Rules are evaluated in rule number order (low → high)
- First match wins → evaluation stops
Rule Components
Stateless implication
- Must allow ephemeral ports outbound (for client → server responses)
- Must allow ephemeral ports inbound (for server → client responses)
- Easy to misconfigure → be careful!
Ephemeral Ports
Linux kernel: 32768-65535
Windows: 49152-65535
NAT Gateway: 1024-65535
→ Best practice: allow 1024-65535 for ephemeral
3. SG vs NACL Comparison
| Feature | Security Group | NACL |
|---|---|---|
| Level | Instance (ENI) | Subnet |
| State | Stateful | Stateless |
| Rules | Allow only | Allow + Deny |
| Default | Deny all inbound, allow all outbound | Allow all (default NACL) / Deny all (custom NACL) |
| Evaluation | All rules | By rule number, first match wins |
| Use | App-level firewall | Backup defense, IP blocking |
| Limit | 60 rules/SG | 20 rules/NACL (soft, max 40) |
| Reference | Can reference other SGs | CIDR only |
Traffic workflow
Inbound packet:
Internet → IGW → NACL (subnet) → SG (instance) → EC2
Outbound packet:
EC2 → SG → NACL → IGW → Internet
→ A packet must pass BOTH the NACL AND the SG to reach its destination.
4. When to use SG vs NACL?
SG (default for most use cases)
- Application-level security
- When you need to reference between SGs (cleaner)
- Stateful → simpler
NACL (additional defense)
- Block a specific IP (SGs cannot Deny)
- Subnet-level rules that apply to many instances
- Compliance requirement (defense in depth)
Combined example
NACL:
- Block known malicious IP (e.g., 1.2.3.4)
- Allow all other traffic
SG:
- Allow HTTP/HTTPS from 0.0.0.0/0
- Allow SSH from corporate CIDR
- Deny others (implicit)
5. Default vs Custom Setup
Default VPC defaults
- Default SG: allow all inbound from the same SG, allow all outbound
- Default NACL: allow all inbound + outbound
Custom VPC defaults
- New SG: deny all inbound, allow all outbound
- Custom NACL: deny all inbound + outbound (you must explicitly add allow rules)
Careful: creating a custom NACL and forgetting the allow rules → blocks all traffic!
6. Cross-Region Security Group Reference
Limitations
- Same region: an SG can reference the SG ID of another VPC (via peering)
- Cross-region: CANNOT reference SG IDs, only CIDRs
7. Common Port Reference
| Service | Port | Protocol |
|---|---|---|
| HTTP | 80 | TCP |
| HTTPS | 443 | TCP |
| SSH | 22 | TCP |
| RDP | 3389 | TCP |
| FTP | 21 | TCP |
| SFTP | 22 | TCP |
| SMTP | 25, 587 | TCP |
| DNS | 53 | TCP/UDP |
| MySQL/Aurora | 3306 | TCP |
| PostgreSQL | 5432 | TCP |
| Microsoft SQL Server | 1433 | TCP |
| Oracle | 1521 | TCP |
| Redis | 6379 | TCP |
| Memcached | 11211 | TCP |
| MongoDB | 27017 | TCP |
| NFS (EFS) | 2049 | TCP |
| ICMP | — | ICMP |
8. VPC Flow Logs
Definition
Flow Logs capture IP traffic information flowing through ENIs.
3 levels
- VPC level: all ENIs in the VPC
- Subnet level: all ENIs in the subnet
- ENI level: 1 specific ENI
Destinations
- CloudWatch Logs
- S3 bucket
- Amazon Data Firehose (formerly Kinesis Data Firehose) → forwards to other destinations
Flow Log Record Format
<version> <account-id> <interface-id> <srcaddr> <dstaddr>
<srcport> <dstport> <protocol> <packets> <bytes>
<start> <end> <action> <log-status>
Example records
2 111111111111 eni-1234 10.0.1.5 8.8.8.8 32768 53 17 1 64 1432917027 1432917087 ACCEPT OK
2 111111111111 eni-1234 192.168.1.1 10.0.1.5 12345 22 6 1 60 1432917027 1432917087 REJECT OK
Decode:
srcaddr: 192.168.1.1 (attempting SSH)dstport: 22action: REJECT (blocked by SG/NACL)
Custom Format (extended)
- You can add fields:
pkt-srcaddr,pkt-dstaddr,traffic-path,tcp-flags,vpc-id,subnet-id... - Useful for debugging complex routing
Use cases
- Debug connectivity issues (REJECT records)
- Security audit (who connected to what)
- Compliance logging
- Network anomaly detection
Flow Logs do not capture
- Traffic to the Amazon DNS server (default DNS)
- DHCP traffic
- Traffic to the default VPC router
- Traffic to/from default Reserved IPs (network/broadcast)
- Mirror traffic (use VPC Traffic Mirroring)
9. VPC Traffic Mirroring (Brief)
Definition
Traffic Mirroring = copy network traffic from an ENI to a destination (security appliance, IDS).
Characteristics
- Captures full packets (unlike Flow Logs, which are metadata only)
- Sends to the ENI/NLB of a security tool
- Filter by VPC/subnet/protocol
- Use case: DPI, IDS/IPS, threat hunting
10. Common Network Issues Debug
"Cannot SSH to EC2"
- SG inbound: allow port 22 from your IP?
- NACL inbound: allow port 22?
- NACL outbound: allow ephemeral 32768-65535?
- Route table: 0.0.0.0/0 → IGW?
- Public IP assigned to the instance?
- OS firewall (ufw, iptables)?
"EC2 cannot reach internet"
- Public subnet: route 0.0.0.0/0 → IGW + has a Public IP?
- Private subnet: route 0.0.0.0/0 → NAT GW?
- NAT GW in a public subnet with an EIP?
- Source/Dest check (NAT instance)?
- SG outbound allows it?
- NACL allows it?
"Web traffic does not reach EC2"
- ALB SG: allow 443 from 0.0.0.0/0?
- EC2 SG: allow the ALB port from the ALB SG (reference)?
- Target Group health check passing?
- App listening on the right port?
Review Questions
-
What is the allowed VPC CIDR range? (/X to /Y)
Show answer
/16 (65,536 IPs) to /28 (16 IPs). The VPC CIDR should be within the private IP ranges: 10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16. You cannot change the primary CIDR after creating the VPC, but you can add secondary CIDR blocks. Each subnet loses 5 IPs (network, VPC router, DNS, reserved, broadcast).
-
How many IGWs can each VPC attach?
Show answer
1 IGW per VPC (1-to-1 relationship). An IGW is highly available, redundant, horizontally scaled — not a SPOF. An IGW can only be attached to 1 VPC at a time. If you need internet access for many VPCs across many accounts, use Transit Gateway + the centralized egress VPC pattern.
-
Why should you have a NAT Gateway in each AZ?
Show answer
A NAT Gateway is AZ-scoped — it only serves traffic in its own AZ. If you only have 1 NAT GW in AZ-a: (1) Private instances in AZ-b must route through AZ-a → higher latency + cross-AZ data transfer cost ($0.01/GB), (2) If AZ-a fails, all private instances lose internet access. One NAT GW per AZ = HA + lower cross-AZ cost.
-
What is the core difference between a Public subnet and a Private subnet?
Show answer
The core point is the route table: a Public subnet has the route
0.0.0.0/0 → IGW— instances can reach the internet directly (if they have a Public IP). A Private subnet has no route to the IGW — outbound internet must go through a NAT Gateway. A subnet is not public/private by itself — the routing table decides. Instances in a public subnet still need a Public IP to receive inbound traffic from the internet. -
What is the 2024 pricing change for Public IPv4?
Show answer
Since February 2024, AWS charges $0.005/hour for all Public IPv4 addresses (both Elastic IPs and auto-assigned IPs), even when the instance is running. Previously, only unattached Elastic IPs were charged. Reason: IPv4 address scarcity. To reduce cost: move to IPv6 (free), use Private IP + ALB, or release unused IPs.
-
How many route tables can 1 subnet be associated with?
Show answer
1 route table at a time. If a subnet is not explicitly associated with any route table, it uses the VPC's main route table (default). But 1 route table can be associated with many subnets. Changing a subnet's route table association takes effect immediately — it does not affect active traffic.
-
Does VPC Peering support transitive routing?
Show answer
No. VPC Peering does not support transitive routing: if A peers with B and B peers with C, A cannot reach C through B. You must create a direct A-C peering. This is a design limitation. If you need hub-and-spoke or transitive routing between many VPCs, use Transit Gateway — it supports transitive routing via attachments.
-
When should you use Transit Gateway instead of VPC Peering?
Show answer
Use Transit Gateway when: (1) You have many VPCs to connect (>5) — peering = N×(N-1)/2 connections, TGW = N connections, (2) You need transitive routing, (3) You connect cross-account and cross-Region (TGW peering between regions), (4) You need to connect VPN and Direct Connect to many VPCs through 1 hub, (5) You need a centralized routing policy. VPC Peering is simpler and cheaper for 2-5 VPCs.
-
What problem does AWS IPAM solve?
Show answer
AWS IP Address Manager (IPAM) solves IP address space management in a multi-account environment: avoiding overlapping CIDRs when creating VPCs, centralized visibility into IP allocation across accounts/Regions, automatic allocation of CIDR blocks from predefined pools, and an audit history of IP assignments. No more manual spreadsheets to track VPC CIDRs.
-
What does VPC Sharing via RAM let you do?
Show answer
VPC Sharing (via AWS Resource Access Manager) lets you share subnets from a VPC (owner account) with other accounts in the same AWS Organization. Participant accounts can deploy resources (EC2, RDS...) into the shared subnets without creating their own VPC. It reduces the number of VPCs to manage, avoids overlapping CIDRs, and centralizes networking in one account.
- SG is stateful, NACL is stateless — briefly explain what that means.
Show answer
Stateful (SG): if an inbound request is allowed, the response is automatically allowed — no separate outbound rule needed. The SG tracks connection state. Stateless (NACL): each packet is evaluated independently — allowing inbound does not automatically allow the response. You need both an inbound rule (port 80) AND an outbound rule for ephemeral ports (32768-65535) for the response to get back to the client.
- When a NACL allows inbound port 80, do you need an outbound rule for the response?
Show answer
Yes — NACLs are stateless, so you need an explicit outbound rule for the response. The server responds on ephemeral ports (Linux: 32768-65535, Windows: 49152-65535). The NACL outbound rule must allow this range. Best practice: allow outbound 0.0.0.0/0 on the NACL, or at least allow the ephemeral port range, and use SGs for fine-grained control.
- Can an SG have Deny rules?
Show answer
No — Security Groups only have Allow rules. By default all inbound is denied (implicit deny), and you can only add Allow rules. To block specific traffic, use a NACL (which has both Allow and Deny rules). NACL Deny rules are useful for blocking specific IPs, malicious traffic, or emergency blocks — something you cannot do with an SG.
- Can Flow Logs capture DNS traffic to Amazon DNS?
Show answer
No. VPC Flow Logs do not capture some traffic: DNS traffic to/from the Amazon DNS server (169.254.169.253), traffic to the DHCP server, the Instance Metadata Service (169.254.169.254), Amazon Time Sync Service, and Windows license activation traffic. To monitor DNS queries, use Route 53 Resolver Query Logging.
- To block 1 specific malicious IP, do you use an SG or a NACL?
Show answer
NACL — because NACLs support Deny rules. SGs only have Allow rules and cannot block a specific IP. A NACL applies at the subnet level, and rules are evaluated by number from low to high — add a Deny rule with a low number (higher priority) before the Allow rules. Note: if you need to block at large scale or by multiple criteria, WAF or Shield Advanced is more effective.
Hands-on Exercises
Part 1: VPC Fundamentals
- Create a Custom VPC
10.0.0.0/16with 4 subnets (2 public, 2 private across 2 AZs) - Attach an IGW to the VPC, configure the public route table
- Launch a NAT Gateway in a public subnet, configure the private route table
- Launch EC2 in a private subnet, test outbound internet (curl ifconfig.io)
- Enable IPv6 for the VPC, test IPv6 connectivity
- Allocate an EIP, attach it to EC2, observe the Public IP change
Part 2: Subnets and Routing
- Create 2 VPCs (10.0/16 and 10.1/16), peer them, test connectivity
- Set up VPC Sharing: share 1 subnet from Account A to Account B (requires 2 accounts)
- Create a private subnet with 0/0 → NAT GW, test EC2 outbound internet
- Set up AWS IPAM (free tier), allocate a CIDR for a new VPC
- Compare cost: VPC Peering vs Transit Gateway for 5 VPCs
Part 3: Security Groups and NACLs
- Create an SG for a web server (ports 80, 443, 22 from the VPC CIDR)
- Create an SG for the DB that only allows MySQL from the app server's SG (reference SG)
- Create a custom NACL with rules: allow HTTP, HTTPS, ephemeral. Block 1 IP.
- Enable VPC Flow Logs sent to S3
- Test blocked connectivity ↔ check the Flow Logs
REJECTrecord - Set up an ACL rule to deny the attacking IP, observe Flow Logs
References
- Amazon VPC User Guide
- VPC and Subnets
- NAT Gateways
- Internet Gateway
- Public IPv4 Pricing
- VPC Peering
- Transit Gateway
- VPC Sharing
- AWS IPAM
- Global Accelerator
- Security Groups
- Network ACLs
- VPC Flow Logs
- Traffic Mirroring