Privacy Policy
© 2025 linux101.dev

ufw Command

ufw, or Uncomplicated Firewall, is a user-friendly front-end for managing iptables. It is the default firewall management tool on Ubuntu and is designed to make common firewall tasks easy without needing to learn the complex syntax of iptables.

Basic Management

Check Firewall Status

sudo ufw status

Shows whether the firewall is active or inactive. To see the configured rules, use sudo ufw status verbose.

Enable the Firewall

sudo ufw enable

Activates the firewall. It will typically start on boot after being enabled.

Disable the Firewall

sudo ufw disable

Deactivates the firewall.

Managing Rules

Allow a Service by Name

sudo ufw allow ssh

Allows incoming traffic for a known service. ufw knows the default ports for many services (e.g., ssh is 22, http is 80). This is the same as sudo ufw allow 22.

Allow a Specific Port

sudo ufw allow 8080/tcp

Allows incoming traffic on a specific port and protocol. If you don't specify a protocol, the rule applies to both TCP and UDP.

Deny a Port

sudo ufw deny 3306

Blocks all incoming traffic on the specified port (e.g., the default MySQL port).

Allow Traffic from a Specific IP

sudo ufw allow from 123.45.67.89

Allows all incoming traffic from a specific IP address.

Delete a Rule

sudo ufw delete allow ssh

Deletes a previously added rule. You must specify the exact rule you want to remove.