ufw

Linux · Network · reference only

What it does

Simple firewall (Uncomplicated Firewall): it allows or blocks traffic with easy-to-read rules, on top of iptables.

Syntax

ufw [opciones] orden

Options and parameters

  • status [verbose|numbered]

    Shows whether it is active and the current rules.

  • enable

    Enables the firewall and keeps it active at boot.

  • disable

    Disables the firewall.

  • allow regla

    Allows traffic, for example 22/tcp or an application name.

  • deny regla

    Blocks traffic.

  • delete regla

    Removes a rule, by its text or by its number.

  • default allow|deny incoming|outgoing

    Changes the default policy.

  • reset

    Disables the firewall and deletes all rules.

Usage examples

  • sudo ufw status verbose

    Shows the status, policies and rules.

  • sudo ufw allow 22/tcp

    Allows SSH connections.

  • sudo ufw deny from 203.0.113.5

    Blocks all traffic from that address.

  • sudo ufw enable

    Enables the firewall.

Notes and common mistakes

  • If you manage the machine over SSH, allow port 22 before running enable or you will lose access.
  • It is installed with sudo apt install ufw; by default it blocks incoming traffic and allows outgoing.

Related commands