ThunderHosting
EN

Opening ports on your VPS firewall (ufw) and common ports

ThunderHosting ·

DeutschFrançaisItaliano

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

bash
# 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 enable

For 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

bash
sudo ufw status numbered
sudo ufw delete 3            # number from the list
sudo ufw delete allow 80/tcp # or by rule

A 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

PortProtocolService
22TCPSSH, SFTP
21TCPFTP
25TCPSMTP (mail between servers)
53TCP/UDPDNS
80TCPHTTP
443TCPHTTPS
465TCPSMTPS (sending mail over TLS)
587TCPSMTP (sending mail (submission))
110 / 995TCPPOP3 / POP3S
143 / 993TCPIMAP / IMAPS
3306TCPMySQL, MariaDB (Database)
5432TCPPostgreSQL (Database)
6379TCPRedis
25565TCPMinecraft Java Edition
19132UDPMinecraft 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.