$linuxjunkies
>

ufw(8)

Uncomplicated Firewall (ufw) is a user-friendly interface for managing iptables firewall rules on Linux.

UbuntuDebianFedoraArch

Synopsis

ufw [OPTION] [RULE]

Description

ufw simplifies firewall management by providing an intuitive command-line interface to configure Linux's iptables rules without requiring deep networking knowledge. It's particularly popular on Ubuntu and Debian-based systems.

Rules can allow or deny traffic based on port numbers, protocols, and IP addresses. The firewall can be toggled on and off globally, and rules are applied immediately and persist across reboots.

By default, incoming traffic is denied and outgoing traffic is allowed, following a secure-by-default principle.

Common options

FlagWhat it does
enableTurn on the firewall
disableTurn off the firewall
statusShow firewall status and list all active rules
allowAdd a rule to allow incoming traffic
denyAdd a rule to block incoming traffic
deleteRemove a rule
resetReset firewall to default settings (all rules removed)
reloadReload firewall rules without disabling it
--dry-runShow what would be done without applying changes
default allow|denySet default policy for incoming or outgoing traffic
insertInsert a rule at a specific position in the ruleset
show addedDisplay rules added (not defaults)

Examples

Enable the firewall and activate all configured rules

sudo ufw enable

Allow incoming SSH connections on port 22 over TCP

sudo ufw allow 22/tcp

Allow MySQL connections from a specific IP address

sudo ufw allow from 192.168.1.100 to any port 3306

Deny all incoming HTTP traffic on port 80

sudo ufw deny 80/tcp

Allow SSH connections using the named service (equivalent to port 22/tcp)

sudo ufw allow ssh

Display all rules with line numbers for easy reference and deletion

sudo ufw status numbered

Remove the rule allowing HTTP traffic

sudo ufw delete allow 80/tcp

Set the default policy to deny all incoming connections

sudo ufw default deny incoming

Related commands