Wiki
Home › Root servers › Firewall with ufw

Firewall with ufw

Open only the required ports.

The SSH rule must be set before ufw enable. Otherwise you lock yourself out.
  1. Install:
    sudo apt install -y ufw
  2. Set the default rules:
    sudo ufw default deny incoming
    sudo ufw default allow outgoing
  3. Allow SSH (adjust if you changed the SSH port):
    sudo ufw allow OpenSSH
  4. Add only the services you need, e.g. a web server:
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
  5. Enable and check:
    sudo ufw enable
    sudo ufw status verbose

Why a firewall directly on the VM?

Ports you should not block

The console (IPMI/KVM) does not go through ufw. It therefore remains reachable even with a wrong firewall rule, see IPMI and console.

Game servers and Docker

Docker containers often publish ports past ufw. If you use Docker, check this separately. For game ports, only open the ports the game really needs.