Set up a firewall with UFW on Ubuntu and Debian
UFW is the simple firewall for Ubuntu and Debian. Allow SSH first with sudo ufw allow OpenSSH, then turn UFW on with sudo ufw enable and type y. On Debian, install it first with sudo apt install -y ufw. Open a port with sudo ufw allow 443/tcp and check with sudo ufw status. To delete a rule, run sudo ufw status numbered, then sudo ufw delete and the rule's number.
Before you start
- You can connect to your server with SSH.
- You know where the browser console is. It gets you back in if a rule blocks SSH.
- On Ubuntu, UFW is already installed but turned off. On Debian, install it first with
sudo apt install -y ufw. - On AlmaLinux, Rocky or Fedora? Use firewalld instead.