VPC is region-wise, by default you can create max 5 VPC. Range of IP Address are defined for each VPC.
CIDR Range: Range of IP address in a network.
Example
CIDR:- 192.168.0.0/16
Because we are using /16 so 192.168 will be constant whereas other octates can be changed from 0-255 which means it has 256x256 = 65536 IP Addresses.
Valid IP Address in this Range
192.168.10.20, 192.168.200.10,192.168.2.0/24, 192.168.3.10/21
Invalid IP in the above CIDR
192.168.10.278, 192.169.0.0/24
Reserved IP Addresses in a network
These reserve IP addresses can not be used for EC2 instances:
1. Network IP
2. Broadcast IP
3. Future use IP
Lab
Create a VPC
1. Search for VPC service
2. Click on Your VPC Link
3. Click Create VPC button
4. On this Page define properties related to VPC
Select VPC only option
Name: irfan-vpc
IPV4 CIDR: 10.10.0.0/16
Tenancy : Default
5. Click on Create VPC button
Create Subnets (By Default no subnet get created in the VPC)
1. Click on Subnets link
2. Click on Create subnet
--------------------------------------------------------------------------
3. Set following properties for Public Subnet
4. Click on Create Subnet
----------------------------------------------------------------------------------------
5. Set following properties for Private subnet
6. Click on Create Subnet
Create an Internet Gateway to provide Internet connectivity to Public subnet
1. Click on Internet Gateways
2. Name: IGW1
3. Select Internet Gateway IGW1 and Action--->Attach to VPC and select myvpc-1
Now Internet connectivity is available to myvpc-1 VPC.
Create Route Tables (A default Route table get created for VPC)
1. Click on Route Tables link
2. Click on Create Route table button
3. Set following properties for Public Subnet
- VPC ID: irfan-vpc
- Subnet Name: irfan-public-subnet-2a
- Availability Zone: 2a
- CIDR: 10.10.1.0/24
4. Click on Create Subnet
----------------------------------------------------------------------------------------
5. Set following properties for Private subnet
- VPC ID: irfan-vpc
- Subnet Name: irfan-private-subnet-2b
- Availability Zone: 2b
- CIDR: 10.10.2.0/24
6. Click on Create Subnet
Create an Internet Gateway to provide Internet connectivity to Public subnet
1. Click on Internet Gateways
2. Name: IGW1
- Click on Create Internet Gateway
3. Select Internet Gateway IGW1 and Action--->Attach to VPC and select myvpc-1
Now Internet connectivity is available to myvpc-1 VPC.
Create Route Tables (A default Route table get created for VPC)
1. Click on Route Tables link
2. Click on Create Route table button
--------------------------------------------------------------------------------------------
3. Set the properties
- Name: Public Route
- VPC: irfan-vpc
-----------------------------------------------------------------------------------------------
5. Set the properties
- Name: Private Route
- VPC: irfan-vpc
Attach subnets to Route tables
1. Select Public Route
2. Select Subnet Associations
3. Click on Edit subnet associations and select Public Subnet 1-a
4. Click on Routes --> Edit Routes--> Add Route
5. Destination: 0.0.0.0/0
6. Target: IGW1
7. click on Save Changes button.
---------------------------------------------------------------------------------------------
1. Select Public Route
2. Select Subnet Associations
3. Click on Edit subnet associations and select Public Subnet 1-a
4. Click on Routes --> Edit Routes--> Add Route
5. Destination: 0.0.0.0/0
6. Target: IGW1
7. click on Save Changes button.
---------------------------------------------------------------------------------------------
1. Select Private Route
2. Select Subnet Associations
3. Click on Edit subnet associations and select Private subnet 1-b
Create EC2 instance in irfan-vpc
1. Create a Public EC2 instance Amazon Linux Image
2. Select VPC as irfan-vpc
3. Select subnet as Public Subnet 1-a
4. Auto assign Public IP: Enable
5. Create new Security Groups for SSH let's call it sshSG.
2. Select Subnet Associations
3. Click on Edit subnet associations and select Private subnet 1-b
Create EC2 instance in irfan-vpc
1. Create a Public EC2 instance Amazon Linux Image
2. Select VPC as irfan-vpc
3. Select subnet as Public Subnet 1-a
4. Auto assign Public IP: Enable
5. Create new Security Groups for SSH let's call it sshSG.
--------------------------------------------------------------------------------------------
1. Create a Private EC2 instance Amazon Linux Image
2. Select VPC as myvpc-1
3. Select subnet as Private Subnet 1-b
4. Auto assign Public IP: Disable
5. Select sshSG security group
1. Create a Private EC2 instance Amazon Linux Image
2. Select VPC as myvpc-1
3. Select subnet as Private Subnet 1-b
4. Auto assign Public IP: Disable
5. Select sshSG security group
Experiment
1. Private IP addresses are in the defined range of subnets or not.
1. Private IP addresses are in the defined range of subnets or not.
Ans: yes
2. Both instances can ping to each other with private ip address.
2. Both instances can ping to each other with private ip address.
Ans: no UNLESS you add the security group - ICMP:IPV4 !!!
Now if you want to connect to the private subnet,
you need to connect to it via the public subnet:
1. copy the key-pair info (.pem)
2. create the key-pair info into your public subnet:
vi IrfanSydney.pem
copy the content over
save :wq!
3. go to the private instance and click connect, choose via ssh, then it will tell you the steps:
chmod 400 IrfanSydney.pem
ssh -i "IrfanSydney.pem" ec2-user@10.10.2.184
No comments:
Post a Comment