We will create a VPC with a public and private subnet and try accessing them both from internet. We will be creating the VPC without using the Wizard available.
Steps:
-
Log in to the AWS console and go to VPC dashboard.
-
Go to ‘Your VPCs’ and click on ‘Create VPC’
-
Provide a name (e.g. BuddyVPC), CIDR (e.g. 10.0.0.0/16) and select ‘Default’ Tenancy.
-
Note: Default tenancy is shared; you may also select ‘Dedicated’.
-
-
Click ‘Yes, Create’
-
-
Verify following:
-
No new subnets are created. Subnets for default VPC will be present anyway.
-
There is a new Route table for the new VPC.
-
No new internet gateways are created.
-
Default security group was created for the new VPC.
-
Default Network ACL was created for the new VPC.
-
-
Click on subnets tab and click on ‘Create Subnet’
-
Provide name (e.g. 10.01.0-ap-southeast-1a), select our VPC, select the availability zone (e.g. ap-southeast-1a) and enter CIDR block range (e.g. 10.0.1.0/24).
-
Note: Specifying the range and AZ in name can be handy at times).
-
-
Click ‘Yes, Create’
-
-
Click on subnets tab and click on ‘Create Subnet’
-
Provide name (e.g. 10.0.2.0-ap-southeast-1b), select our VPC, select the availability zone (e.g. ap-southeast-1b) and enter CIDR block range (e.g. 10.0.2.0/24).
-
Click ‘Yes, Create’
-
-
Click on Internet Gateways and click ‘Create Internet Gateway’.
-
Provide a name (e.g. BuddyIGW).
-
Click ‘Yes, Create’
-
Note: IG is needed to make the subnet public.
-
-
-
Select our IGW, click on ‘Attach to VPC’ and attach to our VPC.
-
Add a new Route out for the VPC
-
Go to ‘Route Tables’ tab.
-
Verify the routes tab for the default route.
-
Note: Good practice to not edit the default root table.
-
-
Click on ‘Create Route table’
-
Provide a name (e.g. BuddyPublicRoute) and select our VPC.
-
Click ‘Yes, Create’
-
-
Select our Route table, go to Routes tab, click edit.
-
Provide a route out entry: Destination as 0.0.0.0/0, Target as our IGW.
-
Click save
-
-
-
Click on Subnet Associations tab and click Edit
-
Select the first subnet (e.g. one in ap-southeast-1a)
-
Make sure that our new route table is currently selected.
-
-
Click Save
-
-
Go to ‘Subnets’ tab, select first subnet, click on ‘Subnet Actions’, click on ‘Auto Assign Public IP’ and select Auto Assign public IP checkbox.
-
Launch an EC2 instance selecting our VPC and into subnet 1
-
Create a bootup script during instance creation to install updates, install httpd, start it and configure it to start on restart, and create an index.html file with some text in /var/www/html. (see previous notes)
-
Create or reuse an EC2 security group with HTTP.
-
Once launched and started, try accessing the public ip to see the index.html page loaded.
-
Also try to SSH into the EC2 instance.
-
-
Launch an EC2 instance selecting our VPC and into subnet 2
-
Create or reuse an EC2 security group with:
-
SSH, MySQL, All ICMP.
-
All sources as custom and IP ranges as: 10.0.1.0/24.
-
ICMP is required as we will be pinging the instance from the other Ec2 instance.
-
-
Verify that it does not have a public IP, but only a private IP
-
-
Login to the public IP EC2 instance and elevate permissions (e.g. sudo su)
-
Try pinging private EC2 instance using the private IP.
-
Ping should be successful
-
-
Copy your .pem private key to the public EC2 instance.
-
Or create a new .pem file and copy the key contents.
-
-
Run: ssh ec2-user@<private-ip> -i mykeypair.pem
-
Should successfully ssh into private instance
-
-
Try running: yum update -y
-
Should not update as there is no valid route out defined.
-
References (Deprecated):
- heartin's blog
- Log in or register to post comments
Recent comments