ufw(8)
Uncomplicated Firewall (ufw) is a user-friendly interface for managing iptables firewall rules on Linux.
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
| Flag | What it does |
|---|---|
enable | Turn on the firewall |
disable | Turn off the firewall |
status | Show firewall status and list all active rules |
allow | Add a rule to allow incoming traffic |
deny | Add a rule to block incoming traffic |
delete | Remove a rule |
reset | Reset firewall to default settings (all rules removed) |
reload | Reload firewall rules without disabling it |
--dry-run | Show what would be done without applying changes |
default allow|deny | Set default policy for incoming or outgoing traffic |
insert | Insert a rule at a specific position in the ruleset |
show added | Display rules added (not defaults) |
Examples
Enable the firewall and activate all configured rules
sudo ufw enableAllow incoming SSH connections on port 22 over TCP
sudo ufw allow 22/tcpAllow MySQL connections from a specific IP address
sudo ufw allow from 192.168.1.100 to any port 3306Deny all incoming HTTP traffic on port 80
sudo ufw deny 80/tcpAllow SSH connections using the named service (equivalent to port 22/tcp)
sudo ufw allow sshDisplay all rules with line numbers for easy reference and deletion
sudo ufw status numberedRemove the rule allowing HTTP traffic
sudo ufw delete allow 80/tcpSet the default policy to deny all incoming connections
sudo ufw default deny incoming