How do I set up a firewall on my VPS? Print

  • 0

Use the firewall tool that fits your OS, then allow only the ports you actually need (such as SSH 22, HTTP 80, HTTPS 443).

Ubuntu/Debian (ufw):

  1. sudo ufw allow OpenSSH
  2. sudo ufw allow 80,443/tcp
  3. sudo ufw enable

AlmaLinux/CentOS (firewalld):

  1. sudo firewall-cmd --permanent --add-service=http --add-service=https
  2. sudo firewall-cmd --reload

If you run a control panel, CSF is a popular alternative. Always keep your SSH port open before enabling the firewall, or you may lock yourself out, the VNC console in your VPS control panel can rescue you. On unmanaged plans this is your job; managed customers can open a ticket.


Was this answer helpful?

« Back