El plan de seguridad The security plan

Para asegurarnos de que todo funcione sin bloqueos accidentales, aplicaremos estas reglas clave:

  1. Política de entrada bloqueada por defecto (DROP): nadie podrá entrar al servidor si no hay una regla explícita que lo permita.
  2. Permitir tráfico de salida: tu servidor podrá conectarse a internet para actualizarse o descargar portadas en Jellyfin.
  3. Mantener conexiones establecidas (Stateful): si el servidor pide algo hacia afuera, el cortafuegos dejará entrar la respuesta automáticamente.
  4. Permitir tráfico local interno (lo / localhost): para que las aplicaciones se comuniquen entre sí internamente.
  5. Permitir la interfaz de Tailscale (tailscale0): para que tengas acceso total remoto a todos tus servicios (Jellyfin, qBittorrent, SSH) sin importar qué puertos usen, pero solo desde tus dispositivos de la red privada.
  6. Permitir tráfico local de casa (opcional pero recomendado): para que tus dispositivos conectados al WiFi de casa sigan viendo a Jellyfin directamente sin pasar por Tailscale si no quieres.

To make sure everything works without accidental lockouts, we'll apply these key rules:

  1. Default-deny inbound policy (DROP): nobody can reach the server unless there's an explicit rule allowing it.
  2. Allow outbound traffic: your server can reach the internet to update itself or fetch cover art in Jellyfin.
  3. Keep established connections (Stateful): if the server requests something outbound, the firewall will let the response back in automatically.
  4. Allow internal loopback traffic (lo / localhost): so applications can talk to each other internally.
  5. Allow the Tailscale interface (tailscale0): so you get full remote access to all your services (Jellyfin, qBittorrent, SSH) regardless of the ports they use, but only from your private network's devices.
  6. Allow local home traffic (optional but recommended): so your devices on the home WiFi keep seeing Jellyfin directly without going through Tailscale if you'd rather not.

Paso a paso para configurar nftables Step by step: setting up nftables

Conéctate por SSH a tu Debian y sigue estos pasos:

Connect to your Debian machine over SSH and follow these steps:

Paso 1: Instalar y habilitar nftables

Asegúrate de que la herramienta esté instalada y se ejecute al encender el sistema:

sudo apt update && sudo apt install nftables -y
sudo systemctl enable nftables

Make sure the tool is installed and starts automatically on boot:

Paso 2: Crear el archivo de reglas

Vamos a sobrescribir la configuración por defecto de nftables creando un archivo limpio con nuestra estrategia. Abre el archivo de configuración con el editor:

sudo nano /etc/nftables.conf

Borra todo lo que haya dentro y copia y pega el siguiente bloque completo:

#!/usr/sbin/nft -f

flush ruleset

table inet filter {
    chain input {
        type filter hook input priority filter; policy drop;

        # 1. Permitir tráfico de loopback (comunicación interna del servidor)
        iif "lo" accept

        # 2. Permitir conexiones ya establecidas o relacionadas (Stateful Firewall)
        ct state established,related accept

        # 3. Rechazar paquetes inválidos por seguridad
        ct state invalid drop

        # 4. Permitir todo el tráfico a través de la interfaz de Tailscale
        iifname "tailscale0" accept

        # 5. Permitir tráfico de tu red local de casa (IPs 192.168.1.X)
        # Ajusta "192.168.1.0/24" si tu red local usa otro rango (ej. 192.168.0.0/24)
        ip saddr 192.168.1.0/24 accept

        # 6. Permitir PING (ICMP) para diagnóstico local
        ip protocol icmp accept
    }

    chain forward {
        type filter hook forward priority filter; policy drop;
    }

    chain output {
        type filter hook output priority filter; policy accept;
    }
}

Nota sobre el guardado: presiona Ctrl + O, luego Enter para guardar, y Ctrl + X para salir.

We're going to overwrite nftables' default configuration with a clean file containing our strategy. Open the config file with the editor, clear everything inside it, and paste in the block above. Saving note: press Ctrl + O, then Enter to save, and Ctrl + X to exit.

Paso 3: Probar y aplicar la configuración

Para asegurarnos de que la sintaxis sea correcta antes de activarlo permanentemente, ejecuta un chequeo de prueba:

sudo nft -c -f /etc/nftables.conf

Si no devuelve ningún mensaje de error, ¡todo está perfecto! Ahora reinicia el servicio de nftables para aplicar el cortafuegos de inmediato:

sudo systemctl restart nftables

To make sure the syntax is correct before enabling it permanently, run a test check. If it doesn't return any error message, everything's perfect! Now restart the nftables service to apply the firewall immediately.

¿Cómo comprobar que el cortafuegos está funcionando? How to check the firewall is working

Para ver el estado real de tu cortafuegos y las reglas que se están aplicando en tiempo real, puedes ejecutar:

sudo nft list ruleset

Verás tu tabla estructurada. A partir de este momento:

  • Cualquier intento de acceso desde internet fuera de tu red local o fuera de tu red Tailscale será rechazado automáticamente.
  • Tu acceso por SSH desde la red local o desde Tailscale seguirá funcionando al 100%.
  • Jellyfin, qBittorrent y las actualizaciones automáticas no tendrán ninguna interrupción.

To see the real status of your firewall and the rules being applied in real time, you can run the command above. You'll see your structured table. From this point on:

  • Any access attempt from the internet outside your local network or your Tailscale network will be rejected automatically.
  • Your SSH access from the local network or from Tailscale will keep working 100%.
  • Jellyfin, qBittorrent, and automatic updates won't have any interruption.