AWS VPC - What is the difference between Internet Gateway & NAT

+5 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,280 points
13,898 views

13 answers to this question.

+3 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.

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
answered Apr 24, 2018 by Flying geek
• 3,160 points

selected Aug 2, 2018 by Priyaj
+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 Aug 2, 2018 by findingbugs
• 4,750 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.

answered Nov 27, 2018 by Shuvodip Ghosh
+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 by aws training in chennai

edited Feb 8 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.

https://www.besanttechnologies.com/training-courses/cloud-computing-training/amazon-web-services-training-institute-in-chennai

answered Feb 8 by aws
+1 vote
IGW applied in VPC level  whereas NGW is applied at instance level
answered Jun 23 by anonymous

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,090 points

edited Oct 16, 2018 by Archana 784 views
0 votes
1 answer
0 votes
2 answers
+1 vote
1 answer
0 votes
1 answer
+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
• 56,920 points
2,129 views