Ports, TCP and UDP
How one address serves many services.
An IP address finds the machine. A port (0 to 65535) finds the service on it. A full connection is identified by address and port: 203.0.113.5:443.
| Port | Service |
|---|---|
| 22 | SSH |
| 25 | SMTP (mail between servers) |
| 53 | DNS |
| 80 | HTTP |
| 443 | HTTPS |
| 3306 | MySQL |
| 5432 | PostgreSQL |
TCP vs UDP
- TCP: connection-oriented, reliable, ordered. Used by web, email, SSH.
- UDP: no connection and no delivery guarantee, but very low overhead. Used by DNS queries, video calls, games and QUIC (HTTP/3).
Firewalls
A firewall allows or blocks traffic by address, port and protocol. The safe default is to deny everything and open only the ports you need.
Test a connection
ping example.com # is the host reachable?
nc -zv example.com 443 # is port 443 open?
ss -tlnp # which ports is this machine listening on? (Linux)
traceroute example.com # path packets takeNoteSome hosts do not answer ping on purpose, so a failed ping does not always mean the host is down.
Try it
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.