VPC Notes
VPC Notes
=> A VPC allows users to create and manage their own isolated virtual networks
within the cloud.
=> In a VPC, users can define their own IP address range, subnets, route tables,
and network gateways. It provides control over network configuration, such as
setting up access control policies, firewall rules, and network traffic routing.
=> Overall, a VPC provides a flexible and secure network environment that enables
users to build and manage their cloud-based applications and infrastructure with
greater control and customization.
###################
VPC Terminology
##################
1) VPC
2) CIDR Blocks
3) Subnets (public and private)
4) Route Tables
5) Internet Gateway
6) NAT Gateway
7) VPC Peering
8) Security Groups
9) NACL
###################
Types of IP's
###################
=> There are several types of IP (Internet Protocol) addresses used in computer
networks. Here are the most common types:
1) IPV4
2) IPV6
3) Public IP
4) Priate IP
5) Dynamic IP
6) Static IP Address
-> Daily billions of new devices launching and they are using internet
-> If a device wants to use internet then ip is mandatory (we are running out of
ips)
==================
IPV4
==================
=> IPv4 addresses are 32-bit numeric addresses written in four sets of numbers
separated by periods (e.g : 192.168.0.1)
=> It is the most widely used IP version and supports approximately 4.3 billion
unique addresses
=> However, due to the increasing number of devices connected to the internet, IPv4
addresses are running out, leading to the adoption of IPv6.
==================
IPV6
==================
=> IPv6 addresses are 128-bit alphanumeric addresses written in eight sets of four
hexadecimal digits separated by colons (e.g.,
2001:0db8:85a3:0000:0000:8a2e:0370:7334)
=> IPv6 provides a significantly larger address space than IPv4, with approximately
340 undecillion unique addresses.
=> It was introduced to overcome the IPv4 address exhaustion issue and support the
growing number of internet-connected devices.
==========
PUblic Ip
===========
===========
Private IP
===========
============
Dynamic IP
===========
===========
Static IP
===========
==================
VPC Sizing
==================
Note: /24 we will get 256 IPs those are sufficient for our usecases in realtime
##########################
*VPC Lab Task For Today*
##########################
1) Create VPC (it will create on Route Table by default name it as private route
table)
6) Attach IGW to Public Route Table so that associated subnet will become public
7) Create One EC2 VM in public subnet and another EC2 vm in private subnet
=====================
Step-1 : Create VPC
=====================
Note: One Route Table will be created for VPC by default. Rename it as "Ashokit-
Private-Route-Table"
===========================
Step-2 : Create 2 Subnets
===========================
-----------------------
Create Subnet-1
----------------------
-> Create Subnet
Name : public-subnet-az-1
------------------------
Create Subnet-2
-------------------------
-> Create Subnet
Name : private-subnet-az-1b
-> AWS will reserve 5 ips in every subnet (we will get only 251)
=================================
Stpe-3 : Create Internet gateway
=================================
Note: By default one IGW will be available and it will be attached to default VPC
-> Attach this IGW to VPC (we can attach IGW to only one VPC)
=================================
Step-4 : Create Route Table
=================================
Note: When we create VPC, we will get only route table by default. It is called as
Main route table.
-> Goto route table and attach route tables to subnets (Subnets association for
Route Tables)
==========================================
Step-5 : Making Subnet as public
==========================================
-> Subnet Associations -> Edit SNET -> Select Public Subnet
======================================
Step - 6 : Create EC2 (Public EC2)
======================================
-> Choose AMI
-> Select VPC
-> Select Public Subnet
-> Assign Public IP as Enable
-> Add SSH and Http Protocols
-> Download KeyPair
-> Launch Instance
========================================
Step - 7 : Create EC2 (Private EC2)
========================================
-> Choose AMI
-> Select VPC
-> Select Private Subnet
-> Assign Public IP as Enable
-> Add SSH (source : custom, Range : 10.0.0.0/16)
-> Download KeyPair
-> Launch Instance
=================================
Step - 8 : Test EC2 Connections
=================================
-> Connect to Public EC2 using MobaXterm (It should allow to connect)
-> Connect to Private EC2 using MobaXterm (It shouldn't allow to connect)
=================================================================================
Step - 9 : Connect with 'private-ec2' from 'public-ec2' using 'ssh' connection
=================================================================================
Note: As both Ec2 instances are available under same VPC, we should be able to one
machine from another machine.
------------------------------
Procedure to access
------------------------------
-> Upload pem file into public-ec2 machine (in mobaxterm we have upload option)
-> Execute below command to make ssh connection from public-ec2 to private-ec2
-> Try to ping google from private ec2 (it should not allow because igw is not
available)
=============================
VPC with NAT Gateway Lab Task
=============================
1) Create NAT gateway in public subnet
3) After NAT Gateway, we should be able to ping google from 'private-ec2' also
#######################
What is VPC Peering
#######################
VPC Peering: IPV4 or IPV6 traffic routes between VPCs created to establish
communication between one or more multiple VPCs.
=======================
AWS definition:
=======================
=> “A VPC peering connection is a networking connection between two VPCs that
enables you to route traffic between them using private IPv4 addresses or IPv6
addresses.
=> Instances in either VPC can communicate with each other as if they are within
the same network. “
1) Through VPC Peering, traffic stays within the AWS network and not go over the
internet.
2) Non-overlapping CIDRs – The 2 VPCs you are trying to peer, must have a mutually
exclusive set of IP ranges.
(If VPC A & B have peered and VPC A & C have peered, VPC B & C cannot share
contents until there is an exclusive peering done between VPC B & C)
===========================
Will VPC Peering Cost me?
===========================
No. VPC itself won’t cost you, however, the resources deployed inside the VPC and
data transfers are done will cost you.
==================================================
Let’s create VPC Peering to enable communication
==================================================
=> On the left navigation panel under VPC -> Peering Connections:
=> Now you would see the status Pending Acceptance which means, Requestor has sent
a request to the peer now target VPC needs to accept the request.
=> Go to VPC Peering -> Click on Actions -> Accept Request
Now navigate to Route Tables, in Default VPC RT(Route Table) -> Edit routes
172.31.0.0/16 - local
0.0.0.0/0 - Internet-gateway
10.0.0.0/16 - vpc peering (We need to add this)
10.0.0.0/16 - local
0.0.0.0/0 - Internet-gateway
172.31.0.0/16 - vpc (We need to add this)
Edit Security Group of Default and Custom VPC to allow traffic from each other
############ Create EC2 instance under Customer VPC with below user data script
###########
############ Create EC2 instance under Default VPC with below user data script
###########
===============================================================
Q ) What is the difference between NACL and Security Groups ?
===============================================================
================
Security Group
================
-> Security Group supports only Allow rules (by default all rules are denied)
-> Security Groups are applicable at the instance level (manually we have to attach
SG to instance)
-> Multiple Security Groups can be attached to single instance & one instance can
have 5 security groups
-> Security Group acts as First Level of defense for Outgoing traffic
======
NACL
======
-> NACL rules are applicable for all the resources which are part of that Subnet
-> NACL acts as first level of Defense for Incoming Traffic ( Security Group acts
as First Level of defense for Outgoing traffic )
===================================================================================
=======================================================================