AWS VPC - What is the difference between Internet Gateway NAT

+9 votes

What is an Internet Gateway? What is a NAT Instance? What services do they offer?
After reading AWS VPC documentation, I observed that they both map private IP addresses to internet route-able addresses for the outgoing requests and then they route the incoming responses of the internet to the requester on the subnet.

So what are the differences between them? What scenarios do I use a NAT Instance instead of (or beside) an Internet Gateway? Are they essentially EC2 instances running some network applications or are they special hardware like a router?

Instead of simply pointing to AWS documentation links, can anyone please explain these by adding some background on what is public and private subnets so any amateur with limited knowledge of networking can understand these easily? Also, when should I use a NAT Gateway instead of a NAT instance?

Apr 24, 2018 in AWS by Cloud gunner
• 4,670 points
128,465 views
The difference is that with NAT(and NAT GW) you can make a request to the internet(if configured) and get a response but the internet cannot initiate a connection to your VPN, with the internet Gateway it can

17 answers to this question.

+4 votes
Best answer

Internet Gateway

An Internet Gateway is a logical connection between an Amazon VPC and the Internet. It is nota physical device. Only one can be associated with each VPC. It does not limit the bandwidth of Internet connectivity. (The only limitation on bandwidth is the size of the Amazon EC2 instance, and it applies to all traffic -- internal to the VPC and out to the Internet.)

If a VPC does not have an Internet Gateway, then the resources in the VPC cannot be accessed from the Internet (unless the traffic flows via a corporate network and VPN/Direct Connect).

A subnet is deemed to be a Public Subnet if it has a Route Table that directs traffic to the Internet Gateway.

You can learn more about this in the AWS Training

NAT Instance

A NAT Instance is an Amazon EC2 instance configured to forward traffic to the Internet. It can be launched from an existing AMI, or can be configured via User Data like this:

#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
/sbin/iptables -t nat -A POSTROUTING -o eth0 -s 0.0.0.0/0 -j MASQUERADE
/sbin/iptables-save > /etc/sysconfig/iptables
mkdir -p /etc/sysctl.d/
cat <<EOF > /etc/sysctl.d/nat.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.send_redirects = 0
EOF



Instances in a private subnet that want to access the Internet can have their Internet-bound traffic forwarded to the NAT Instance via a Route Table configuration. The NAT Instance will then make the request to the Internet (since it is in a Public Subnet) and the response will be forwarded back to the private instance.

Traffic sent to a NAT Instance will typically be sent to an IP address that is not associated with the NAT Instance itself (it will be destined for a server on the Internet). Therefore, it is important to turn off the Source/Destination Check option on the NAT Instance otherwise the traffic will be blocked.

NAT Gateway

AWS introduced a NAT Gateway Service that can take the place of a NAT Instance. The benefits of using a NAT Gateway service are:

  • It is a fully-managed service -- just create it and it works automatically, including fail-over
  • It can burst up to 10 Gbps (a NAT Instance is limited to the bandwidth associated with the EC2 instance type)

However:

  • Security Groups cannot be associated with a NAT Gateway
  • You'll need one in each AZ since they only operate in a single AZ

For a more detailed demarcation and a simplified explanation, check this out  https://www.youtube.com/watch?v=XjPUyGKRjZs

You can also check AWS SysOps training to learn more.

answered Apr 24, 2018 by Flying geek
• 3,280 points

edited Jul 10, 2023 by Khan Sarfaraz
This Answer does tell what is the signifiant of IGW and NAt, but it does not tell why we can't use NAT instead of IGW or vice vera since both will help Instances to access Internet.
You can think in this way, say you have two subnets. You launch instances in both the subnets. Now if you attach IGW in of the subnets, that subnet becomes public. It means outside world can connect to that subnet. Means your instance is accessible from outside and your instance can connect to the outside world.

But if you have a requirement that outside world will not able to connect to your instance, then that time you have to use NAT in your subnet and your subnet becomes private subnet. So every instance on that subnet can connect to the outside world but outside world will not able to connect to your instances.

An Internet Gateway (IGW) allows resources within your VPC to access the internet, and vice versa. In order for this to happen, there needs to be a routing table entry allowing a subnet to access the IGW.

That is to say - an IGW allows resources within your public subnet to access the internet, and the internet to access said resources.

A NAT Gateway does something similar, but with two main differences:

  1. It allows resources in a private subnet to access the internet (think yum updates, external database connections, wget calls, etc), and

  2. it only works one way. The internet at large cannot get through your NAT to your private resources unless you explicitly allow it.

Let me add one more thing to this answer. NAT instances are old stuff.  you should not use NAT instance if you can. NAT Gateway is highly available- not just one instance once you add it across multiple AZs. NAT Instance is an individual EC2 instance and therefore a single point of failure.
+2 votes

An Internet Gateway (IGW) allows resources within your VPC to access the internet, and vice versa. In order for this to happen, there needs to be a routing table entry allowing a subnet to access the IGW.

That is to say - an IGW allows resources within your public subnet to access the internet, and the internet to access said resources.

A NAT Gateway does something similar, but with two main differences:

  1. It allows resources in a private subnet to access the internet (think yum updates, external database connections, wget calls, etc), and

  2. it only works one way. The internet at large cannot get through your NAT to your private resources unless you explicitly allow it.

Get ready to level up your skills as an AWS Developer! Join our comprehensive AWS Developer Associate certification Course!
answered Aug 2, 2018 by findingbugs
• 4,780 points
+2 votes

An internet gateway serves two purposes: to provide a target in your VPC route tables for internet-routable traffic, and to perform network address translation (NAT) for instances that have been assigned public IPv4 addresses.

Hope this helps!

Check out this AWS DevOps Certification to become an expert.

Thanks!

answered Nov 27, 2018 by Shuvodip Ghosh

edited Jul 10, 2023 by Khan Sarfaraz
+1 vote

A NAT device forwards traffic from the instances in the private subnet to the internet or other AWS services, and then sends the response back to the instances while Internet Gateway is used to allow resources in your VPC to access internet.

answered Nov 27, 2018 by Trisha
+1 vote

You can use a NAT instance in a public subnet in your VPC to enable instances in the private subnet to initiate outbound IPv4 traffic to the Internet, this will prevent the instances from receiving inbound traffic initiated by someone on the Internet.

While Internet gateway is used to allow objects in your VPC to access internet.

answered Nov 27, 2018 by Jhaji
+1 vote
You can refer to the below documentation from Amazon.

Here you can understand briefly about NAT Instances and how to setup a NAT Instance.
answered Nov 27, 2018 by coderunner
+1 vote

The NAT instance makes it possible for instances in private subnets to access the Internet. It needs an Elastic IP, but the instances in your private subnet doesn't. If you don't use private subnets or don't have a need to enable Internet access from there, you don't need any NAT instance.

Internet Gateway is like the access door for your instances to access Internet.

answered Nov 27, 2018 by Murli V
+1 vote
You can see a brief difference between NAT Instance and NAT Gateway here in the documentation provided by Amazon

https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-comparison.html
answered Nov 27, 2018 by Rupali
+2 votes

An Internet Gateway (IGW) allows resources within your VPC to access the internet, and vice versa. In order for this to happen, there needs to be a routing table entry allowing a subnet to access the IGW.

That is to say - an IGW allows resources within your public subnet to access the internet, and the internet to access said resources.

A NAT Gateway does something similar, but with two main differences:

  1. It allows resources in a private subnet to access the internet (think yum updates, external database connections, wget calls, etc), and

  2. it only works one way. The internet at large cannot get through your NAT to your private resources unless you explicitly allow it.

answered Dec 10, 2018 by Nabarupa Das
+1 vote
For instances to use the IGW to access the internet they need a public IP so that the response can be routed back (basically a pass through).

While utilizing a NAT means that any of your instances regardless of public IP or not can access the internet as it is more of a proxy than a pass through.
answered Dec 10, 2018 by 404notfound
+1 vote

NAT will allow private instances (without a public IP) to access the Internet, but not the other way around. So, for the EC2 instances that need to be available to theInternet, you need to assign a public IP. ... A public subnet means a subnet that hasinternet traffic routed through AWS's Internet Gateway.

answered Feb 8, 2019 by aws training in chennai

edited Feb 8, 2019 by Vardhan
+1 vote

An Internet Gateway (IGW) allows resources within your VPC to access the internet, and vice versa. In order for this to happen, there needs to be a routing table entry allowing a subnet to access the IGW.

That is to say - an IGW allows resources within your public subnet to access the internet, and the internet to access said resources.

A NAT Gateway does something similar, but with two main differences:

  1. It allows resources in a private subnet to access the internet (think yum updates, external database connections, wget calls, etc), and

  2. it only works one way. The internet at large cannot get through your NAT to your private resources unless you explicitly allow it.

answered Feb 8, 2019 by aws
+1 vote
IGW applied in VPC level  whereas NGW is applied at instance level
answered Jun 24, 2019 by anonymous
0 votes

An Internet Gateway (IGW) allows resources within your VPC to access the internet, and vice versa. In order for this to happen, there needs to be a routing table entry allowing a subnet to access the IGW.

That is to say - an IGW allows resources within your public subnet to access the internet, and the internet to access said resources.

A NAT Gateway does something similar, but with two main differences:

  1. It allows resources in a private subnet to access the internet (think yum updates, external database connections, wget calls, etc), and

  2. it only works one way. The internet at large cannot get through your NAT to your private resources unless you explicitly allow it.

answered Mar 13, 2020 by Rakesh
• 140 points
0 votes

NAT device forwards traffic from the instances in the private subnet to the internet or other AWS services, and then sends the response back to the instances while Internet Gateway is used to allow resources in your VPC to access internet.

answered May 16, 2020 by varsha
• 140 points
0 votes
NAT Gateways (AWS-managed) helps your VPC instances connect with the internet. These Public Subnets have a route to the internet gateway.

NAT Instances (Self-managed) allows the instances in your Private Subnets to access the internet while remaining private.
answered Sep 23, 2020 by Theseus
• 140 points
0 votes

Hi,

You can think in this way, say you have two subnets. You launch instances in both the subnets. Now if you attach IGW in one of the subnets, that subnet becomes public. It means the outside world can connect to that subnet. It means your instance is accessible from outside and your instance can connect to the outside world.

But, if you have a requirement that the outside world will not able to connect to your instance, then that time you have to use NAT in your subnet and your subnet becomes a private subnet. So every instance on that subnet can connect to the outside world, but the outside world will not able to connect to your instances.

answered Dec 14, 2020 by MD
• 95,460 points

Related Questions In AWS

0 votes
1 answer

What is the difference between EBS snapshots & AMI?

The major difference is between the type ...READ MORE

answered Oct 16, 2018 in AWS by Archana
• 4,170 points

edited Oct 16, 2018 by Archana 10,575 views
0 votes
1 answer

What is the difference between AWS Ops Work and Cloud Formation?

AWS Ops Work is an application management ...READ MORE

answered Dec 14, 2018 in AWS by Shuvodip
1,785 views
0 votes
2 answers

What is the difference between VPC security group and EC2 security group?

EC2-Classic Security Group When the instance is launched, ...READ MORE

answered Feb 11, 2019 in AWS by Ramaya
4,319 views
+1 vote
1 answer

What is the difference between an Instance, AMI and Snaphots in AWS?

AMI is the Amazon Machine Image which provides ...READ MORE

answered May 24, 2019 in AWS by ArchanaNagur
• 2,360 points
4,215 views
0 votes
2 answers
+1 vote
3 answers
+1 vote
3 answers

Which is better ? AWS S3 bucket logs vs AWS cloudtrail

CloudTrail logs API calls accessed to your ...READ MORE

answered Aug 16, 2018 in AWS by Priyaj
• 58,020 points
7,374 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP