AWS Certified Developer - Associate
Networking Fundamentals
Internet Gateway Demo
In this lesson, you will learn how to convert a private subnet into a public subnet so that any EC2 instance deployed within becomes accessible from the Internet. We will create a VPC, a subnet, and then attach an Internet Gateway—all from scratch.
Create a VPC
First, log into the AWS Management Console and navigate to the VPC page. Create a new VPC using the IPv4 CIDR block 10.0.0.0/16. (Assigning an IPv6 CIDR block is optional for this exercise.)
Create a Subnet
Next, create a subnet within the newly created VPC. Name this subnet "public subnet" and assign it the CIDR block 10.0.1.0/24.
After creating the subnet, deploy an EC2 instance into it. By default, an instance launched into this subnet will not have Internet access.
Launch an EC2 Instance
- Open the EC2 page in a new tab and click on Launch Instance.
- Name the instance (e.g., "my public server") and select the Amazon Linux AMI.
- Choose the default instance type (t2.micro – covered by the free tier) and select an existing key pair for SSH access.
Under Network Settings, edit the configuration to select the VPC you created earlier. With only one subnet available (the public subnet), select it and enable Auto-assign Public IP so that the instance receives a public IP address.
Next, configure the security group. The default security group allows SSH (port 22) from any IP (0.0.0.0/0). Optionally, you can add an ICMP rule to allow ping traffic. Proceed to launch the instance.
Wait a few moments until the instance is initialized. Then, check the instance list to confirm that the server is running and has been assigned a public IP address.
Review the instances view to verify that the instance is running and note its public IP address. Even though a public IP is assigned, the instance remains unreachable from the Internet by default.
Test network connectivity by pinging or attempting to SSH into the instance. For example, run the following commands in your terminal:
ping 54.159.89.36
ssh -i aws-demo.pem [email protected]
Note
Both the ping
and ssh
commands will hang or time out because the subnet is private and lacks the necessary Internet routing configuration.
Attach an Internet Gateway
To enable Internet connectivity, you must create and attach an Internet Gateway to your VPC.
- Return to the VPC page and click on the Internet Gateway section.
- Create a new Internet Gateway and give it a name (e.g., "my-internet-gateway").
- Attach the newly created Internet Gateway to your VPC.
Even after attaching the Internet Gateway, the instance remains unreachable because the route table of the subnet has not been updated. Re-run the ping
command to confirm the connection still fails.
Update the Route Table
Next, update the route table to direct traffic destined for the Internet through the Internet Gateway. Follow these steps:
- Check the subnet's route table using the "Route Table" tab in the VPC console. You will notice that only a local route exists.
- Edit the default route table or create a new custom route table (e.g., "public route table") associated with your VPC.
- Associate the route table with the public subnet.
- Add a default route (0.0.0.0/0) that directs all Internet-bound traffic to the Internet Gateway.
After saving the changes, the routing configuration enables Internet access for the EC2 instance. Test the connectivity again by running:
# Attempt to ping and then SSH into the EC2 instance
ping 54.159.89.36
ssh -i aws-demo.pem [email protected]
Initially, the ping may time out, but after a short period the requests should succeed. A successful ping output might resemble:
Pinging 54.159.89.36 with 32 bytes of data:
Reply from 54.159.89.36: bytes=32 time=27ms TTL=112
Note
It may take a few moments for the new routing configuration to propagate.
Conclusion
By following this lesson, you have successfully transformed a private subnet into a public subnet. You accomplished this by creating and attaching an Internet Gateway to your VPC and updating the route table to include a default route for Internet traffic. As a result, any EC2 instance launched into this subnet can now be accessed from the Internet—provided that the necessary network ACLs and security group rules allow the traffic.
All resources deployed in this subnet are now officially public.
For further details, refer to the AWS Documentation.
Watch Video
Watch video content