Basic firewall setup for your server Print

  • firewall, ufw, firewalld, ports, security
  • 0

A firewall blocks every connection to your server except the ones you allow. It's one of the simplest and most effective ways to protect a VPS, VDS or dedicated server.

Golden rule: allow SSH first

Always allow SSH before you turn the firewall on, or you could lock yourself out. If you changed your SSH port, allow that port instead of 22.

Ubuntu and Debian (UFW)

  1. Install UFW if it isn't already there: apt install ufw -y
  2. Allow SSH: ufw allow 22/tcp
  3. Allow web traffic if you run a website: ufw allow 80/tcp and ufw allow 443/tcp
  4. Turn the firewall on: ufw enable
  5. Check what's allowed: ufw status verbose

AlmaLinux, Rocky and CentOS (firewalld)

  1. Start the firewall: systemctl enable --now firewalld
  2. Allow SSH: firewall-cmd --permanent --add-service=ssh
  3. Allow web traffic: firewall-cmd --permanent --add-service=http and firewall-cmd --permanent --add-service=https
  4. Apply the changes: firewall-cmd --reload
  5. Check what's allowed: firewall-cmd --list-all

More good habits

  • Only open the ports you actually use. For example, keep database ports like 3306 closed to the internet unless you really need remote access.
  • Install fail2ban to automatically block IP addresses that keep guessing passwords.
  • Use SSH keys and turn off password login when you're comfortable.

Locked yourself out?

It happens to the best of us. Open a ticket with your server's IP address and we'll help you get back in.

Our network includes DDoS protection on every virtual server plan and on Performance dedicated servers, but it isn't a replacement for a firewall on the server itself.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution