Lesson 06 β Internet Gateway & NAT Gateway
Learning Path
βοΈ Phase 2 β AWS Cloud Security
π Module 04 β Amazon VPC & Network Security
π― Lesson Objective
Section titled βπ― Lesson ObjectiveβBy the end of this lesson, you will be able to:
- Understand Internet Gateways (IGW).
- Understand NAT Gateways.
- Differentiate inbound and outbound Internet traffic.
- Configure Internet connectivity.
- Build Internet Gateway and NAT Gateway using AWS Console.
- Configure routing using Route Tables.
- Verify Internet connectivity.
- Apply enterprise networking best practices.
π Lesson Information
Estimated Time: 120 Minutes
Difficulty: Beginner
Prerequisites: Lesson 05 β Route Tables
Hands-on Lab: Yes
πΌ Business Value
Section titled βπΌ Business ValueβEvery enterprise application has different Internet connectivity requirements.
For example:
| Resource | Internet Required? |
|---|---|
| Public Website | β Yes |
| Application Server | β Outbound Only |
| Database | β No |
| Bastion Host | β Yes |
| Internal API | β No |
Instead of exposing every server to the Internet, AWS provides two networking components:
- Internet Gateway (IGW)
- NAT Gateway
These services allow organisations to securely control inbound and outbound Internet traffic.
π’ CloudNova Scenario
Section titled βπ’ CloudNova ScenarioβCloudNova has deployed:
- Public Load Balancer
- Application Servers
- Database Servers
Requirements:
- Customers must access the website.
- Application servers must download software updates.
- Databases must never communicate directly with the Internet.
The Cloud Security Team decides to use:
- Internet Gateway
- NAT Gateway
π What is an Internet Gateway?
Section titled βπ What is an Internet Gateway?βAn Internet Gateway (IGW) is a highly available AWS-managed component that enables communication between your VPC and the Internet.
It allows:
- Incoming Internet traffic
- Outgoing Internet traffic
An Internet Gateway is attached to a VPC.
Without an Internet Gateway, resources inside the VPC cannot communicate directly with the Internet.
π Internet Gateway Architecture
Section titled βπ Internet Gateway ArchitectureβInternet
β
Internet Gateway
β
Public Route Table
β
Public Subnet
β
Application Load Balancer
β
EC2Only resources in Public Subnets can use the Internet Gateway.
π What is a NAT Gateway?
Section titled βπ What is a NAT Gateway?βA NAT (Network Address Translation) Gateway allows resources in Private Subnets to initiate outbound Internet connections while preventing inbound Internet access.
Typical uses include:
- Operating system updates
- Installing software packages
- Downloading application dependencies
- Accessing AWS APIs
- Connecting to external services
Users on the Internet cannot initiate connections to instances behind a NAT Gateway.
NAT Gateway Architecture
Section titled βNAT Gateway ArchitectureβPrivate EC2
β
Private Route Table
β
NAT Gateway
β
Internet Gateway
β
InternetNotice:
Internet traffic always passes through the Internet Gateway because the NAT Gateway itself resides in a Public Subnet.
Internet Gateway vs NAT Gateway
Section titled βInternet Gateway vs NAT Gatewayβ| Internet Gateway | NAT Gateway |
|---|---|
| Public Internet access | Private outbound access |
| Supports inbound & outbound traffic | Outbound traffic only |
| Attached directly to VPC | Deployed inside Public Subnet |
| Used by Public Subnets | Used by Private Subnets |
| No Elastic IP required | Requires an Elastic IP |
π CloudNova Enterprise Architecture
Section titled βπ CloudNova Enterprise ArchitectureβInternet
β
Internet Gateway
β
ββββββββββββββββββββββββ
Public Subnet
β
Application Load Balancer
β
Bastion Host
β
NAT Gateway
ββββββββββββββββββββββββ
β
Private App Subnet
β
EC2
Containers
ββββββββββββββββββββββββ
β
Private Database Subnet
β
Amazon RDSThis architecture follows AWS Well-Architected best practices.
π Lab 01 β Create an Internet Gateway (AWS Console)
Section titled βπ Lab 01 β Create an Internet Gateway (AWS Console)βOpen
AWS Console
β
VPCNavigate to
Internet Gateways
β
Create Internet GatewayConfigure
| Setting | Value |
|---|---|
| Name | CloudNova-IGW |
Click
Create Internet GatewayAttach Internet Gateway
Select:
CloudNova-IGW
β
Actions
β
Attach to VPCChoose
CloudNova-VPCClick
Attachπ Lab 02 β Update Public Route Table
Section titled βπ Lab 02 β Update Public Route TableβNavigate to:
Route Tables
β
Public-RT
β
Routes
β
Edit RoutesEnsure the following route exists:
| Destination | Target |
|---|---|
| 10.10.0.0/16 | Local |
| 0.0.0.0/0 | Internet Gateway |
Save Changes.
π Lab 03 β Allocate an Elastic IP
Section titled βπ Lab 03 β Allocate an Elastic IPβNavigate to
VPC
β
Elastic IP Addresses
β
Allocate Elastic IPAccept defaults.
Click
AllocateRecord the Elastic IP Allocation ID.
π Lab 04 β Create NAT Gateway
Section titled βπ Lab 04 β Create NAT GatewayβNavigate to
VPC
β
NAT Gateways
β
Create NAT GatewayConfigure:
| Setting | Value |
|---|---|
| Name | CloudNova-NAT |
| Subnet | Public-Subnet-A |
| Elastic IP | Select Allocated Elastic IP |
Click
Create NAT GatewayWait until the status changes to:
AvailableThis may take several minutes.
π Lab 05 β Update Private Route Table
Section titled βπ Lab 05 β Update Private Route TableβOpen:
Route Tables
β
Private-RT
β
Routes
β
Edit RoutesAdd:
| Destination | Target |
|---|---|
| 10.10.0.0/16 | Local |
| 0.0.0.0/0 | CloudNova-NAT |
Save Changes.
Now Private Subnets can access the Internet without being publicly accessible.
π» AWS CLI Lab
Section titled βπ» AWS CLI LabβList Internet Gateways
Section titled βList Internet Gatewaysβaws ec2 describe-internet-gatewaysCreate Internet Gateway
Section titled βCreate Internet Gatewayβaws ec2 create-internet-gatewayTag Internet Gateway
Section titled βTag Internet Gatewayβaws ec2 create-tags \ --resources igw-xxxxxxxx \ --tags Key=Name,Value=CloudNova-IGWAttach Internet Gateway
Section titled βAttach Internet Gatewayβaws ec2 attach-internet-gateway \ --internet-gateway-id igw-xxxxxxxx \ --vpc-id vpc-xxxxxxxxAllocate Elastic IP
Section titled βAllocate Elastic IPβaws ec2 allocate-address \ --domain vpcRecord:
AllocationIdCreate NAT Gateway
Section titled βCreate NAT Gatewayβaws ec2 create-nat-gateway \ --subnet-id subnet-public \ --allocation-id eipalloc-xxxxxxxxView NAT Gateway
Section titled βView NAT Gatewayβaws ec2 describe-nat-gatewaysAdd NAT Route
Section titled βAdd NAT Routeβaws ec2 create-route \ --route-table-id rtb-private \ --destination-cidr-block 0.0.0.0/0 \ --nat-gateway-id nat-xxxxxxxxVerify Route Tables
Section titled βVerify Route Tablesβaws ec2 describe-route-tablesβ Verification
Section titled ββ VerificationβYour environment should look like this.
Internet
β
Internet Gateway
β
Public Route Table
β
Public Subnet
β
Application Load Balancer
β
NAT Gateway
β
Private Route Table
β
Private App Subnet
β
Private Database SubnetVerify:
β Internet Gateway attached
β Elastic IP allocated
β NAT Gateway status = Available
β Public Route Table points to IGW
β Private Route Table points to NAT Gateway
π§ͺ Connectivity Test
Section titled βπ§ͺ Connectivity TestβLaunch:
- One EC2 instance in Public-Subnet-A
- One EC2 instance in Private-App-A
Test:
From the Public EC2:
ping google.comExpected:
Replies receivedFrom the Private EC2:
ping google.comor
curl https://aws.amazon.comExpected:
Outbound Internet access works through NAT Gateway.The Private EC2 should not have a Public IPv4 address.
π Troubleshooting
Section titled βπ TroubleshootingβProblem
Section titled βProblemβNo Internet from Public EC2.
Check:
- Internet Gateway attached?
- Public Route Table configured?
- Security Group outbound rule?
- Public IPv4 assigned?
Problem
Section titled βProblemβPrivate EC2 cannot access Internet.
Check:
- NAT Gateway status = Available.
- NAT Gateway is in a Public Subnet.
- Private Route Table points to NAT Gateway.
- Elastic IP attached.
- Outbound Security Group rules.
Problem
Section titled βProblemβNAT Gateway creation fails.
Verify:
- Elastic IP allocated.
- Public Subnet selected.
- Internet Gateway attached to VPC.
π’ Enterprise Notes
Section titled βπ’ Enterprise NotesβCloudNova standards:
- Never place a NAT Gateway in a Private Subnet.
- Deploy one NAT Gateway per Availability Zone for production workloads.
- Monitor NAT Gateway costs using AWS Cost Explorer.
- Use VPC Endpoints for AWS services where possible to reduce NAT traffic.
- Keep databases isolated in Private Subnets.
- Review Route Tables during security assessments.
π« Common Mistakes
Section titled βπ« Common Mistakesββ Forgetting to attach the Internet Gateway.
β Creating the NAT Gateway in a Private Subnet.
β Forgetting the Elastic IP.
β Pointing the Private Route Table directly to the Internet Gateway.
β Deploying databases in Public Subnets.
β Assuming the NAT Gateway allows inbound Internet traffic.
π§ͺ DIY Challenge
Section titled βπ§ͺ DIY ChallengeβUsing your AWS account:
Create:
- CloudNova-IGW
- Elastic IP
- CloudNova-NAT
Configure:
- Attach IGW to CloudNova-VPC.
- Create NAT Gateway in Public-Subnet-A.
- Update Public Route Table.
- Update Private Route Table.
Verify:
- Public EC2 has Internet access.
- Private EC2 has outbound Internet access.
- Private EC2 does not have a Public IPv4 address.
Take screenshots of:
- Internet Gateway
- NAT Gateway
- Elastic IP
- Route Tables
- EC2 networking
- AWS CLI output
π Knowledge Check
Section titled βπ Knowledge Checkβ-
What is an Internet Gateway?
-
What is a NAT Gateway?
-
Why must a NAT Gateway be placed in a Public Subnet?
-
Which AWS resource requires an Elastic IP?
-
Can a Private EC2 instance receive inbound Internet traffic through a NAT Gateway?
-
Which Route Table should contain the Internet Gateway route?
-
Which Route Table should contain the NAT Gateway route?
-
Why do enterprises deploy one NAT Gateway per Availability Zone?
-
What are the security benefits of Private Subnets?
-
How do Internet Gateways and NAT Gateways work together?
π‘ Key Takeaways
Section titled βπ‘ Key TakeawaysβAfter completing this lesson, you should understand:
- An Internet Gateway connects an Amazon VPC to the public Internet.
- A NAT Gateway allows Private Subnets to initiate outbound Internet connections without exposing resources to inbound Internet traffic.
- Public Route Tables use an Internet Gateway, while Private Route Tables use a NAT Gateway.
- NAT Gateways require an Elastic IP address and must be deployed in a Public Subnet.
- Designing Internet connectivity correctly is a fundamental responsibility of Cloud Security Engineers and Cloud Architects.
π Next Lesson
Section titled βπ Next Lessonββ‘οΈ Lesson 07 β Security Groups