πŸ‘ˆ

🌐 AWS Networking – Complete Summary (Notes)


1️. What is an IP address?

An IP address is a unique number used to identify and communicate with a device in a network.

There are two types used in AWS EC2:

  • Private IP
  • Public IP

2️. Why EC2 gets both Private IP and Public IP?

βœ… Private IP

  • Used for internal communication
  • Works only inside the network (VPC)
  • Mandatory for every EC2

βœ… Public IP

  • Used for internet communication
  • Optional
  • Allows users on the internet to access EC2

Simple rule:

  • Public IP β†’ Internet
  • Private IP β†’ Internal network

3️. What makes an IP β€œprivate” or β€œpublic”?

βœ… Private IP

  • Comes from reserved private IP ranges:
    • 10.0.0.0/8
    • 172.16.0.0/12
    • 192.168.0.0/16
  • Internet routers do NOT route these IPs
  • Only usable inside private networks

βœ… Public IP

  • Comes from globally routable internet IP space
  • Unique across the whole internet
  • Routers know how to reach them

4. Why private IP is more secure than public IP?

  • Private IP is not reachable from the internet
  • Internet routers drop private IP traffic
  • Less exposure = less attack surface

Public IP:

  • Visible on the internet
  • Can be scanned or attacked
  • Needs extra security (firewalls, rules)

5. Can routers forward private IP traffic?

  • βœ… Inside your own network (VPC, VPN, office)
  • ❌ Across the public internet

Reason:

  • Internet routers follow global rules (RFC 1918)
  • They never route private IPs

πŸ‘‰ NAT exists to translate private IP to public IP.


6. What happens if I try to connect to EC2 using Private IP?

❌ From internet (your laptop without VPN)

  • Packet is dropped by routers
  • Connection fails

βœ… From same VPC or connected network (VPN)

  • Routing works
  • Security groups checked
  • Connection succeeds

7. Complete flow when connecting to EC2 using Public IP

  1. Laptop sends packet to Public IP
  2. Packet travels through internet
  3. Reaches AWS edge
  4. Goes to Internet Gateway (IGW)
  5. NAT happens (Public IP β†’ Private IP)
  6. Routed inside VPC
  7. NACL checked
  8. Security Group checked
  9. Reaches EC2 via ENI
  10. Application (SSH/HTTP) responds
  11. Return traffic goes back via reverse NAT

βœ… EC2 only sees private IP traffic


8. What is CIDR?

CIDR (Classless Inter‑Domain Routing) defines a range of IP addresses.

Example:

10.0.0.0/16
  • /16 β†’ network size
  • Defines how many IPs are available

Used in:

  • VPC creation
  • Subnets
  • Security Groups
  • NACLs

9. Is CIDR used while creating EC2?

  • ❌ Not directly
  • βœ… Indirectly

Flow:

  • VPC is created with CIDR
  • Subnet is created with CIDR
  • EC2 gets a private IP from subnet CIDR

##What is a VPC?

VPC (Virtual Private Cloud) is:

A logically isolated private network in AWS

It provides:

  • Network isolation
  • IP control
  • Routing
  • Security

πŸ“Œ Every EC2 must be inside a VPC


10. Why do we need a VPC?

We need VPC to:

  • Isolate our resources
  • Control IP ranges
  • Secure traffic
  • Decide internet access

Without VPC:

  • No security
  • No organization
  • No isolation

11. Do we already have a VPC by default?

βœ… Yes

AWS automatically creates a default VPC:

  • Has CIDR (usually 172.31.0.0/16)
  • Has public subnets
  • Has Internet Gateway
  • Ready to launch EC2 immediately

πŸ“Œ Mainly for learning/testing, not production


12. Does a VPC require a CIDR?

βœ… Yes, always.

  • A VPC cannot exist without CIDR
  • CIDR defines all private IPs in the VPC

13. Can two VPCs have the same IP range?

βœ… Yes, as long as they are not connected

Example:

VPC‑1: 10.0.0.0/16
VPC‑2: 10.0.0.0/16

Allowed because:

  • VPCs are isolated
  • Separate routing domains

❌ Not allowed if you try to connect them (peering, VPN)


14. Can EC2s in different VPCs have the same private IP?

βœ… Yes

Example:

EC2 in VPC‑1 β†’ 10.0.1.15
EC2 in VPC‑2 β†’ 10.0.1.15

No issue because:

  • IP uniqueness is required only within the same VPC
  • Each VPC is a separate network

15. Can two EC2s have the same public IP?

❌ No, never.

Reasons:

  • Public IPs must be globally unique
  • Internet routing would break otherwise
  • Enforced by AWS and internet authorities

Elastic IP:

  • Can be moved between EC2s
  • But only one resource at a time

16. Where do private IP and public IP come from?

  • Private IP β†’ Comes from VPC CIDR
  • Public IP β†’ Comes from AWS’s public internet IP pool

Public IP:

  • Is NOT part of VPC
  • Is mapped to private IP using NAT

17. What happens if IPs run out in a VPC or subnet?

  • IP exhaustion is local to that VPC / subnet
  • Other VPCs (even with same CIDR) are NOT affected

If subnet IPs are exhausted:

  • ❌ Cannot launch new EC2
  • ❌ Cannot scale resources
  • βœ… Existing instances keep running

βœ… FINAL GOLDEN RULES (Very Important)

  • Private IPs are unique only inside a VPC
  • Public IPs are unique across the internet
  • Each VPC has its own IP universe
  • IP exhaustion is per subnet / VPC
  • Public IP is a mapping, EC2 internally uses private IP only