The internet gateway, a virtual private cloud (VPC) component, connects our VPC to the internet. It is horizontally scalable, highly available, and compatible with IPv4 and IPv6. It allows resources placed inside the public subnets to exchange data with the internet. If we wanted to initiate a connection between a resource placed on a public subnet and the internet without the internet gateway, we’d require a VPN or AWS Direct Connect; without it, it won’t be possible.
The internet gateway comes free of cost with our AWS account, can be linked to any of our VPCs, and is not specific to any one availability zone. The internet gateway is not physically linked to the VPC because it’s not a physical device; it provides only a virtual connection to and from the internet.
The following diagram illustrates an internet gateway inside the AWS Cloud. By default, each VPC has its route table, with a path that allows for internal communication between the components within a VPC. The first entry of the route table symbolizes this communication. However, a path has to be configured that allows internet traffic to be directed toward the internet gateway—given the name “igw”—as shown in the second entry of the route table.
To receive and transfer data to the internet, we must perform the following configurations and ensure that all our instances have IPv4 or IPv6 addresses.
We will create an internet gateway and associate it with your VPC.
In our route table, we’ll add a route that directs outgoing traffic to the internet gateway.
We’ll also ensure that any security groups and network access control lists allow incoming and outgoing traffic from the instances inside our VPC.
If we want instances inside a private subnet to be accessible via the internet gateway, we also need to configure our NAT gateway; this way, we’ll be able to initiate connections from our private instances to the internet, but this won’t be true the other way around.
To wrap things up, an internet gateway is a VPC component that creates a logical connection between the VPC instances and the World Wide Web. It enables two-way data exchange between them. If we do not link an internet gateway to a VPC, the only other way to communicate with the internet is by VPN.