AWS Virtual Private Cloud (VPC) is a networking service that enables you to launch AWS resources in a logically isolated virtual network that you’ve defined. This virtual network closely resembles a traditional network that you’d operate in your own data center, with the benefits of using the scalable infrastructure of AWS.
This lab will teach you how to create a custom AWS VPC with a public and private subnet. You will also learn how to create an internet gateway and route table to allow the public subnet to access the internet.
Amazon will bill you for any applicable AWS resources and time used that are not covered in the AWS Free Tier.
Part 1: Create a VPC and Subnets
VPCs are used to isolate your AWS resources from the public internet and other VPCs. They define a virtual network that closely resembles a traditional network that you’d operate in your own data center. Subnets are used to divide a VPC into multiple networks. They are used to isolate resources within a VPC from each other. Subnets can be public or private, depending on whether they are connected to the internet.
- Go to the VPC Dashboard in the AWS console.
- Click Create VPC.
- Enter a Name for your VPC.
-
Enter a CIDR block for your VPC.
When creating a VPC, it is important to choose a CIDR block that is large enough to accommodate your needs. You can use a CIDR calculator to help you choose the right CIDR block.
-
Click Create VPC.
When creating subnets, it is important to divide your VPC into logical groups. For example, you may want to create a subnet for web servers, a subnet for database servers, and a subnet for bastion hosts.
- Go to the Subnets page in the AWS console.
- Click Create subnet.
- For VPC, select the VPC you created in step 5.
- For Subnet name, enter Public subnet.
- For Availability Zone, select an availability zone.
- For IPv4 CIDR block, enter a CIDR block for the public subnet.
- Select the Enable auto-assign public IPv4 address checkbox.
- Click Create subnet.
- Repeat steps 7-13 to create a private subnet.
Part 2: Create Internet Gateway
- Go to the Internet gateways page in the AWS console.
- Click Create internet gateway.
- For Name, enter Internet Gateway.
- Click Create internet gateway.
- Go to the Internet gateways page in the AWS console.
- Select the internet gateway you created in step 18.
- Click the Actions tab.
- Click Attach to VPC.
- Select the VPC you created in step 5.
- Click Attach.
Part 3: Create Route Tables
- Go to the Route tables page in the AWS console.
- Click Create route table.
- For Name tag, enter Public route table.
- For VPC, select the VPC you created in step 5.
- Click Create route table.
- Go to the Route tables page in the AWS console.
- Select the public route table you created in step 29.
- Click the Routes tab.
- Click Add route.
- For Destination, enter the CIDR block 0.0.0.0/0.
- For Target, select the internet gateway you created in step 18.
- Click Save.
- Go to the Route tables page in the AWS console.
- Select the public subnet route table you created in step 29.
- Click the Subnet Associations tab.
- Click Add subnet.
- Select the public subnet you created in step 9.
- Click Save.
Part 4: Create Security Groups
- Go to the Security groups page in the AWS console.
- Click Create security group.
- For Security group name, enter Public security group.
- For Description, enter Public security group.
- For VPC, select the VPC you created in step 5.
- Click Create security group.
- Repeat step 43.
- Select the public security group you created in step 48.
-
Click the Inbound rules tab.
Security groups are used to control inbound and outbound traffic to and from your AWS resources. You can use security groups to control traffic based on IP address, port, and protocol.
- Click Edit inbound rules.
- Click Add rule.
- For Type, select SSH.
- For Source, select My IP.
- Click Save rules.
- Go to the Security groups page in the AWS console.
- Repeat steps 43-56 to create a private security group that allows SSH from the public security group.
Part 5: Create EC2 Instances
A bastion host is a server that is used to access other servers in a secure manner. Bastion hosts are typically placed in a public subnet and are configured to only allow SSH traffic from authorized IP addresses. Once you have connected to the bastion host, you can then SSH to other servers in the VPC.
- Go to the EC2 Dashboard in the AWS console.
- Click Launch instance.
- Select the Amazon Linux 2 AMI.
- Select the t2.micro instance type.
- Click Next: Configure Instance Details.
- For Network, select the VPC you created in step 5.
- For Subnet, select the public subnet you created in step 9.
- For Auto-assign Public IP, select Enable.
- Click Next: Add Storage.
- Click Next: Add Tags.
- Click Add Tag.
- For Key, enter Name.
- For Value, enter Public EC2 instance.
- Click Next: Configure Security Group.
- Select the public security group you created in step 48.
- Click Review and Launch.
- Click Launch.
- Select Create a new key pair.
- For Key pair name, enter SSH key pair.
- Click Download Key Pair.
- Click Launch Instances.
- Repeat steps 57-73 to create an EC2 instance in the private subnet using the private security group.
Part 6: Connect to the EC2 Instances
- Go to the EC2 Dashboard in the AWS console.
- Select the public EC2 instance you created in step 73.
- Click Connect.
- Copy the SSH command.
- Open a terminal.
- Paste the SSH command into the terminal.
ssh -i "SSH key pair.pem" ec2-user@<public EC2 instance IP address>
- From the EC2 instance, SSH into the private EC2 instance.
ssh -i "SSH key pair.pem" ec2-user@<private EC2 instance IP address>