A firewall decides which network ports on your VPS are reachable from the internet. Leaving only the services you need open – usually SSH, HTTP and HTTPS – removes most attack surface. Depending on your provider, Virtualizor may offer a firewall in the panel; in all cases you can run a firewall inside the VPS itself.
Before you start
- List the services you run and their ports (see the table below).
- Keep the VNC console available. If a rule blocks SSH, VNC still works.
- If you run a control panel, use its own firewall tool instead – for example the Plesk Firewall or CSF on DirectAdmin – to avoid conflicting rules.
Common ports
| Service | Port |
|---|---|
| SSH | 22/tcp (or your custom port) |
| HTTP / HTTPS | 80/tcp, 443/tcp (and 443/udp for HTTP/3) |
| SMTP / submission | 25, 465, 587/tcp |
| IMAP / POP3 (SSL) | 993, 995/tcp |
| Plesk | 8443/tcp |
| DirectAdmin | 2222/tcp |
| RDP (Windows) | 3389/tcp |
Panel firewall (if available)
Some Virtualizor installations show a Firewall or Security section for the VPS. There you can add rules by protocol, port and source IP, and set a default policy. Panel rules filter traffic before it reaches the VPS, which also helps against floods. Exact options depend on your provider; if the section is not present, use the in-VPS firewall below.
UFW on Ubuntu and Debian
- Allow SSH first:
ufw allow 22/tcp(change if you moved SSH). - Allow web traffic:
ufw allow 80/tcpandufw allow 443. - Set defaults:
ufw default deny incomingandufw default allow outgoing. - Enable:
ufw enable. - Check:
ufw status verbose.
Restrict sensitive ports to your own IP, for example:
ufw allow from 198.51.100.20 to any port 22 proto tcpfirewalld on AlmaLinux and Rocky Linux
- Make sure it runs:
systemctl enable --now firewalld. - Allow services:
firewall-cmd --permanent --add-service=ssh --add-service=http --add-service=https. - Open a custom port:
firewall-cmd --permanent --add-port=2222/tcp. - Apply:
firewall-cmd --reload. - Check:
firewall-cmd --list-all.
Make rules safe to test
Before enabling a new firewall over SSH, schedule an automatic rollback in case you lock yourself out. For example, on Ubuntu run echo "ufw disable" | at now + 5 minutes (install the at package first), enable your rules, confirm that a new SSH session still connects, and then cancel the job with atrm. With firewalld you can test rules without --permanent; they disappear on reload or reboot if something goes wrong.
Add brute-force protection
A firewall blocks ports; Fail2Ban blocks abusive IPs on open ports. Install it to protect SSH and mail; see Fail2Ban jail.local settings.
Troubleshooting
- Locked out of SSH: log in through VNC and run
ufw disableorsystemctl stop firewalld, then fix the rule. - Docker containers bypass UFW: Docker inserts its own rules. Bind published ports to
127.0.0.1or use a reverse proxy. - Website unreachable after enabling: port 80 or 443 is not allowed. Check the rule list.
- Outgoing mail fails: many providers block outbound port 25 by default; ask support.
