๐Ÿ‘ˆ

๐Ÿšช What is a Port?

A port is like a door on a computer or server.

  • IP address โ†’ identifies the machine
  • Port number โ†’ identifies the application/service on that machine

๐Ÿ‘‰ IP = building address ๐Ÿ‘‰ Port = flat/room number


๐Ÿ“ฆ Why Ports are Needed

One server runs many services at the same time:

ServicePort
Website80
Secure Website443
SSH22
Database3306

Without ports: โŒ Computer wouldnโ€™t know which service should receive the data.


๐Ÿ”ข Port Range (Very Important)

Ports range from:

0 โ€“ 65535

Categories:

1๏ธโƒฃ Well-Known Ports (0โ€“1023)

Reserved for common services.

2๏ธโƒฃ Registered Ports (1024โ€“49151)

Used by applications.

3๏ธโƒฃ Dynamic / Ephemeral Ports (49152โ€“65535)

Temporary ports used by clients.


โญ Common Ports You MUST Remember (AWS + Interviews)

PortServiceUse
22SSHLogin to Linux EC2
80HTTPWebsite
443HTTPSSecure website
21FTPFile transfer
25SMTPSend emails
53DNSDomain resolution
3306MySQLDatabase
5432PostgreSQLDatabase
27017MongoDBDatabase
3389RDPWindows login

๐Ÿง  How Ports Work (Simple Flow)

Example: You open a website.

1๏ธโƒฃ Your browser uses a random client port

Example: 52344

2๏ธโƒฃ It connects to server:

Server IP : 443

3๏ธโƒฃ Server replies back to:

Your IP : 52344

โœ” Server port is fixed โœ” Client port is temporary


๐Ÿ” TCP vs UDP Ports

Ports work with protocols.

๐Ÿงฑ TCP (Reliable)

  • Connection-oriented
  • Slower but safe

Used for:

  • HTTP (80)
  • HTTPS (443)
  • SSH (22)

โšก UDP (Fast)

  • No connection
  • Faster but not guaranteed

Used for:

  • DNS (53)
  • Video streaming
  • Gaming

โ˜๏ธ Ports in AWS (Very Important)

Security Group = Firewall

Security Groups control:

  • Which ports are allowed
  • From which IP

Example:

Allow inbound:
Port 22 โ†’ My IP
Port 80 โ†’ 0.0.0.0/0

If port is closed: โŒ Service is running โŒ But cannot be accessed


๐Ÿงช Real AWS Example

You launch EC2 and install Apache.

Apache listens on:

Port 80

But you forget to open port 80 in Security Group.

Result: โŒ Website not accessible

๐Ÿ‘‰ Security Group must allow the port


๐Ÿ›‘ Important AWS Exam Traps

โ— EC2 not accessible? Check:

  1. Security Group
  2. NACL
  3. Correct port
  4. Correct protocol (TCP/UDP)

๐Ÿ” Check Open Ports (Linux)

Check listening ports:

ss -tuln

or

netstat -tuln

๐Ÿง  One-Line Exam Definition

A port is a logical communication endpoint that allows multiple services to run on the same IP address.


๐Ÿ“ Quick Memory Trick

  • 22 โ†’ SSH
  • 80 โ†’ Web
  • 443 โ†’ Secure Web
  • 3306 โ†’ MySQL
  • 5432 โ†’ PostgreSQL