Advertisement
Intermediate AWS, VPC & Networking

How does a NAT Gateway allow resources in a private subnet to access the internet for outbound connections while remaining unreachable from inbound internet traffic?

Short answer

A NAT Gateway is placed in a public subnet and allows instances in a private subnet to initiate outbound connections to the internet, such as downloading software updates, by translating their private IP addresses to the NAT Gateway's own public IP address, while preventing any…

Save AWS mock interview
Advertisement
AModel answer
A NAT Gateway is placed in a public subnet and allows instances in a private subnet to initiate outbound connections to the internet, such as downloading software updates, by translating their private IP addresses to the NAT Gateway's own public IP address, while preventing any unsolicited inbound connections from the internet from ever reaching those private instances directly, giving you outbound internet access without compromising the security benefit of keeping those resources otherwise fully isolated from direct inbound access.
Example

aws ec2 create-nat-gateway --subnet-id subnet-12345 --allocation-id eipalloc-12345

Real-world example
A company's private subnet hosted application servers use a NAT Gateway to download necessary security patches from the internet, while remaining completely unreachable from any inbound connection originating outside the VPC.
Likely follow-ups
  • What is the difference between a NAT Gateway and a NAT Instance?
  • How does NAT Gateway pricing work, and what data transfer costs should be expected?
Related topics