Open Ports in Ubuntu: What They Are and How They Work
What a port is, what makes it open, closed or filtered, which ports common services use, and how Ubuntu decides what the outside world can reach.
3 min readBy Daniel
Reviewed by the AmazingRDP technical team

The best way to understand ports is to run a server. A Linux VPS gives you root access and a public IP address. See Linux VPS from $6.99
"Open the port" is advice everyone running a server hears, often before anyone has explained what a port is. This page is the explanation. For the commands, we have separate guides: check open ports on Ubuntu, open or block a port in the Ubuntu firewall, and the command reference for every distribution.
What a port is
An IP address leads to a machine. A machine runs many network programs at once, so each connection also carries a number from 0 to 65535 that says which program it is for. That number is the port. The address is the building; the port is the door.
There are two sets of ports, one for each transport protocol: TCP, used where every byte must arrive in order (web, mail, SSH, remote desktop), and UDP, used where speed matters more than completeness (DNS lookups, voice, games, VPN tunnels). TCP port 53 and UDP port 53 are different doors.
What "open" means
A port is open when two things are true: a program is listening on it, and nothing in between blocks the way.
| State | What happens to a connection | Cause |
|---|---|---|
| Open | It is accepted | A program is listening and the firewall allows it |
| Closed | It is refused at once | Nothing is listening on that port |
| Filtered | It gets no answer and times out | A firewall drops the packets |
This is why "opening a port in the firewall" alone achieves nothing: without a program behind it, the port is closed all the same.
Ports you will meet
| Port | Protocol | Service |
|---|---|---|
| 22 | TCP | SSH |
| 53 | UDP and TCP | DNS |
| 80, 443 | TCP | Websites (HTTP, HTTPS) |
| 25, 465, 587 | TCP | Sending mail |
| 3306 | TCP | MySQL and MariaDB |
| 5432 | TCP | PostgreSQL |
| 3389 | TCP | Remote Desktop |
| 51820 | UDP | WireGuard |
Ports below 1024 are reserved for system services; only root may start a program on them. The numbers are conventions: SSH can listen on 2222 if you tell it to.
Which address a program listens on
A program chooses not only a port but an address:
127.0.0.1(localhost): reachable only from the machine itself. Databases should usually listen here.0.0.0.0: every address of the machine, so reachable from outside.
Many security problems are simply a service on 0.0.0.0 that was meant for 127.0.0.1.
How Ubuntu decides what gets in
A connection from the internet passes several gates:
- The provider's network or your router. Some providers have a firewall in their control panel; at home, a router lets nothing in without port forwarding.
- Ubuntu's firewall. The tool is
ufw. On a fresh installation it is switched off, which means every listening program is reachable. Once switched on, it refuses incoming connections except those you allow. - The program. It must be running, listening on the right address, and willing to accept you (password, key).
A fresh Ubuntu Server has almost nothing listening, usually only SSH. Ports open when you install services, and a newly installed service often starts and listens at once, without asking.
Why this matters
- Every open port is tested by strangers. Automatic scanners cover the whole internet in hours. A new server sees its first login attempts within minutes.
- Open as little as needed. A web server needs 80 and 443 for everyone. SSH, databases and admin panels should be open for your addresses only, or not at all.
- Look regularly. List what is listening after every installation.
The three commands to remember
sudo ss -tulpn
sudo ufw status verbose
sudo ufw allow 443/tcp
What is listening; what the firewall allows; allow one port. Before switching ufw on over SSH, allow SSH first (sudo ufw allow OpenSSH), or you lock yourself out.
A Linux VPS is a good place to see all of this at work. On Windows, the same ideas apply: see enable a port through PowerShell.
Questions
What is an open port?
A port on which a program is listening and that no firewall blocks, so connections to it are accepted.
Which ports are open by default on Ubuntu?
On Ubuntu Server usually only SSH on port 22. Others open when you install services.
What is the difference between a closed and a filtered port?
A closed port refuses the connection at once because nothing listens there. A filtered port gives no answer because a firewall drops the packets.
Is it dangerous to have open ports?
Only as dangerous as the service behind them. Open what is needed, limit the rest to your own addresses, and keep services updated.