Skip to content

Lesson 2 of 3

TCP, UDP and ports

2 min

An IP address gets data to the right machine. A port gets it to the right program on that machine. Ports are numbered 0 to 65535.

TCP

TCP is connection-based and reliable. It starts with a three-way handshake (SYN, SYN-ACK, ACK), numbers every packet, and resends anything lost. Use it when every byte must arrive in order: web pages, email, file transfer, SSH.

UDP

UDP just sends packets, with no handshake and no guarantee of delivery. It's faster and lighter, which suits DNS lookups, video calls, gaming and streaming, where a late packet is worse than a lost one.

Well-known ports

  • 22 SSH (remote administration)
  • 25, 587 SMTP (sending email)
  • 53 DNS (UDP and TCP)
  • 80 HTTP
  • 443 HTTPS
  • 3306 MySQL, 5432 PostgreSQL
  • 3389 RDP (Windows remote desktop)

A port being open means a program is listening there. Every open port is something an attacker can reach, so close what you don't need and firewall the rest to known IPs.

Firewalls

A firewall decides which traffic is allowed by IP, port and protocol. A common server policy: allow 80 and 443 from anywhere, allow 22 only from the office IP, and block everything else.