Ports: which to open and how to check
Which ports typical services need, how to see what the machine is listening on, how to check external availability, and what to do if a port is closed.
Updated August 23, 2026
A port is a number that tells the system which service should receive an incoming connection. The rule is simple: only what you actually use should be open. Every extra open port is another door that someone will test for weaknesses.
Common port numbers
| Port | Service | Open to the outside |
|---|---|---|
| 22 | SSH | Yes, preferably restricted by address |
| 80 | HTTP | Yes, if you have a website |
| 443 | HTTPS | Yes, if you have a website |
| 25, 465, 587 | Inbound — only if you run your own mail server. Outbound is closed on our side and opened on request | |
| 3306 | MySQL | No, local only |
| 5432 | PostgreSQL | No, local only |
| 6379 | Redis | No, local only |
| 27017 | MongoDB | No, local only |
| 25565 | Minecraft | Yes, if it's a game server |
A note on mail: inbound connections are not restricted, while outbound connections on 25, 465, and 587 are closed at the node level until you ask us to open them. Rules inside the machine do not change this — see Mail server: why it's hard and what to consider for details.
Databases are almost never exposed to the outside. If you need access from your work computer, the right way is an SSH tunnel, not an open port:
ssh -L 5432:127.0.0.1:5432 artem@<address>
What the machine is listening on
ss -tulpn
ss -tlpn | grep 443
lsof -i -P -n | grep LISTEN
Look at the address before the port number. 127.0.0.1:5432 means the service is only available from inside — it isn't reachable from outside, no matter how many rules you add. 0.0.0.0:5432 means the service is open on all network interfaces and must be protected by a firewall.
Checking from the outside
From your computer:
nc -vz <address> 443
curl -I http://<address>
Checking with ping is pointless: ICMP and TCP are different things; a port can work while ping is blocked, and vice versa.
Port is closed: step-by-step troubleshooting
- Is the service running?
systemctl status <service> - Is it listening on the right address?
ss -tulpn— not127.0.0.1 - Does the firewall allow it?
ufw status verboseornft list ruleset - Is Docker interfering? Published container ports bypass ufw
- Check the service logs:
journalctl -u <service> -n 50
The order matters: most often the problem is at step two, not in the firewall.
Changing a service port
For example, moving SSH:
sed -i "s/^#\?Port 22/Port 2222/" /etc/ssh/sshd_config
ufw allow 2222/tcp
sshd -t
systemctl restart ssh
Check that you can log in on the new port in a separate window, and only then remove the rule for port 22. For details, see SSH hardening.
Common mistakes
| Symptom | Cause | Solution |
|---|---|---|
Connection refused | Service is not running | systemctl status, check the logs |
Connection timed out | Packet is dropped by the firewall | Check the rules |
| Works locally, not from outside | Bound to 127.0.0.1 | Change the address in the config |
Address already in use | Port is taken by another service | ss -tulpn and stop the extra service |
Open a port only after checking what is answering on it. A forgotten port from an old experiment is a typical entry point for a hack; see signs of compromise.