Common Ports Cheat Sheet: From 21 to 443, Which One Should You Open

What a Port Is, and Why 65535 of Them

A machine runs web, database and SSH at once. The OS hands each packet to the right app via port numbers: the destination port in the TCP/UDP header decides ownership.

TCP header: [source port][destination port][sequence]…
destination port = which app on this machine handles this connection

0–65535 gives 65536 numbers: 1–1023 are well-known ports (often requiring privileged binding), 1024–49151 registered, and 49152–65535 dynamic/private.

What an Open Port Actually Exposes

"Only open 80/443" is repeated not because those two are safe, but because every extra open port adds a service a scanner can find. Risk is a product of three factors:

Reachability × service weakness × data value. A port that answers is only the first factor — a necessary condition, not proof of compromise. So whether a port should be open is not decided by its number; it is decided by three things:

  • Which address it binds to. Listening on 127.0.0.1 admits only the local machine; 0.0.0.0 admits every reachable interface. The Local Address column in ss -tlnp is the answer, and many people believe a service is internal when it actually binds to 0.0.0.0.
  • Whether the service authenticates. Databases and caches are the usual victims: a publicly reachable 6379 (Redis) or 27017 (MongoDB) with no auth is close to handing over the data directory; exposed 3306 and 5432 move straight into the range of weak-credential brute force.
  • Whether the management plane is naked. 3389 (RDP) and 22 (SSH) are prime targets for credential stuffing and brute force; backup admin ports such as 8443 are often opened temporarily and never closed.

Two further misjudgements:

  1. 443 alone is not safety. Application-layer bugs — injection, broken access control, deserialisation — still hit 443. Minimising exposure removes the "unknown service" layer, not application vulnerabilities.
  2. A private network or NAT is not a boundary. Once an attacker owns one internal host, lateral movement rides precisely on those "internal only" ports; cloud security groups and host firewalls must agree in both layers, and configuring one layer equals configuring none.

Port scanning rests on this: a service answers on the port it listens on, so probing tells you whether a live service exists on an IP. Self-audits and reconnaissance use the same trick — the only difference is who is scanning.

Common Ports by Purpose

Web and Encryption

Port Service Notes
80 HTTP often 301 → 443
443 HTTPS encrypted, a must-open
8443 HTTPS alt web admin / backup; do not leave public

Remote Admin and File Transfer

Port Service Notes
22 SSH / SFTP / SCP change default, keys only, source-IP limits
3389 RDP (Windows) strongly discourage public exposure
21 FTP plaintext; prefer SFTP/SCP
990 FTPS (implicit) encrypted FTP

Databases

Port Service Notes
3306 MySQL/MariaDB usually internal only
5432 PostgreSQL internal only
6379 Redis never expose publicly
27017 MongoDB never expose publicly

Dev and Debug

Port Service Notes
3000 Node/Vite dev local binding is fine
3300 common dev service local use
5000 / 8000 Flask / generic bind to localhost
53 DNS UDP, service-private

Mail and More

Port Service Notes
25 / 587 SMTP / submission 25 often blocked by clouds
110 / 143 POP3 / IMAP plaintext; prefer encrypted
993 / 995 IMAPS / POP3S encrypted, recommended

Source vs Destination Port

  • Destination port = the service's "doorplate" the client connects to;
  • Source port = a random high port the client picks when initiating, so the server can reply to the right flow.

Outbound source ports are random and rarely need opening; only inbound "which destination port to expose" matters. The usual rule: inbound allows the destination ports you need, outbound allows ephemeral high ports.

The Security Baseline, Ranked by Risk

  1. Pull databases and caches inward first: 3306, 5432, 6379 and 27017 bind to the internal network or localhost only, closed by both the security group and the host firewall;
  2. Never leave management naked: 22 and 3389 must have at least one of source-IP limits, a changed port, or key-only auth; put 3389 behind a VPN or jump host;
  3. Web exposes 80/443 only, with 80 permanently 301-ing to 443, and backup ports such as 8443 closed when done;
  4. Rules live in both layers: the cloud security group and the host firewall must agree; never "open everything and fix later";
  5. Scan your own public IP regularly: compare against the listening addresses in ss -tlnp and confirm no debug or admin port was left open.

After the last step, ask once: "does this port really need to be reachable from the internet?" Usually the answer is no, and removing one port removes one attack surface.

Reproducible Results

Do not memorise the table — ask the OS. Python's standard library ships the IANA services database:

import socket
socket.getservbyname("ssh", "tcp")     # → '22'
socket.getservbyname("http", "tcp")    # → '80'
socket.getservbyname("https", "tcp")   # → '443'

The reverse lookup is socket.getservbyport(22). For the full cross-reference (including UDP and middleware ports) see the common ports reference, and generate high ports outside the privileged range with the random port generator.

Frequently Asked Questions

How do 'opening a port' and a service's protocol relate?

A port is just a numeric 0–65535 label; whether to open it depends on whether you need to expose a service outward. Services are grouped by protocol: HTTP/HTTPS (80/443), SSH (22), MySQL (3306)… Ports separate different apps on one machine, while the protocol defines how traffic to that port is interpreted. So opening a port equates to allowing a specific protocol's service to be reachable, which ties to its security strength (encrypted? authenticated?)—why 443 is often safer to expose than 21 or 3389.

What is the difference between source and destination ports?

The destination port is the service's listening port the client connects to (websites = 443); the source port is a temporary high port the client picks randomly (usually 1024–65535) so the server can reply to the right flow. So: to serve outbound you only care about destination ports; outbound source ports are random and rarely need fixing open. Firewall rules likewise are mostly 'restrict inbound to needed destination ports; outbound allows ephemeral high ports'.

How do I quickly find what is occupying a port?

Shell tools vary: Linux ss -tlnp/netstat -tlnp shows listening ports and owning process; Windows netstat -ano gives the PID to look up with tasklist; macOS lsof -i :port. To cross-link a port with a public IP and whether a service actually answers, pair it with IP/DNS-lookup tools rather than guessing. If your real question is 'may I open this port outward', probing the target IP for a listening service beats speculation.

What is a server port security baseline?

Core is least privilege: allow only what must be public, deny the rest. Baseline: web = 80/443 only (prefer 443, redirect 80); SSH on an alternate port or key-only with frequent rotation and, ideally, source-IP limits; databases, Redis, Docker and debug ports (e.g. 5000/3000) should never be exposed to the public internet—bind to internal/localhost only; use cloud security groups (inbound only 22/80/443/app ports); and periodically scan your own public IP to confirm no admin management port is accidentally open. Verify exact numbers with a port/random-port tool before writing rules.

← Back to Blog