Opening ports on your VPS firewall (ufw) and common ports
Open and close ports on an Ubuntu VPS with ufw without locking yourself out, check which services listen, and look up the ports common services use.
On a VPS you decide which ports are open. The control panel does not filter incoming traffic to your VPS, so the firewall inside the server is what protects it. On Ubuntu Server the simplest firewall is ufw, which is installed but usually not active on a new server.
Before you start
Always allow SSH (port 22) before you switch the firewall on, otherwise you lock yourself out. If it happens anyway, log in with Open console on the Console tab of the server page and fix the rules.
Open ports with ufw
# show the current state
sudo ufw status verbose
# allow SSH first, then the ports you need
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# switch the firewall on
sudo ufw enableFor UDP services add /udp, for example sudo ufw allow 19132/udp. A port range needs the protocol: sudo ufw allow 27015:27030/udp. ufw applies each rule to IPv4 and IPv6.
Close a port again
sudo ufw status numbered
sudo ufw delete 3 # number from the list
sudo ufw delete allow 80/tcp # or by ruleA port is open in ufw but still not reachable? Check that the service runs and listens on the public address: sudo ss -tulpn lists all listening ports. A service bound to 127.0.0.1 only accepts connections from the server itself.
Common ports
| Port | Protocol | Service |
|---|---|---|
| 22 | TCP | SSH, SFTP |
| 21 | TCP | FTP |
| 25 | TCP | SMTP (mail between servers) |
| 53 | TCP/UDP | DNS |
| 80 | TCP | HTTP |
| 443 | TCP | HTTPS |
| 465 | TCP | SMTPS (sending mail over TLS) |
| 587 | TCP | SMTP (sending mail (submission)) |
| 110 / 995 | TCP | POP3 / POP3S |
| 143 / 993 | TCP | IMAP / IMAPS |
| 3306 | TCP | MySQL, MariaDB (Database) |
| 5432 | TCP | PostgreSQL (Database) |
| 6379 | TCP | Redis |
| 25565 | TCP | Minecraft Java Edition |
| 19132 | UDP | Minecraft Bedrock Edition |
Do not open database ports such as 3306, 5432 or 6379 to the whole internet. Allow only the addresses that need them, for example sudo ufw allow from 203.0.113.10 to any port 3306 proto tcp, or connect through an SSH tunnel.
Locked out or need the console? See Managing your VPS.
Related articles
Related products
Still need help?
Open a ticket and our support team in Ticino will help you.
Open a ticket