# Uncomplicated Firewall (UFW)

> A small firewall tool on Ubuntu. You type short rules like allow 22.

**Field:** Infrastructure  
**Category:** Linux & the Command Line  
**Also known as:** UFW, ufw Command, Ubuntu Firewall

## Think of it like

Think of it like a light switch for a hard machine. You press easy buttons, and it does the hard part.

## Definition

UFW is a simple firewall tool that comes with Ubuntu. Its name is short for Uncomplicated Firewall. You give it short rules, like allow 22. It turns them into the longer rules the system needs underneath. It is off when Ubuntu is first installed, so you must turn it on yourself.

## Example

Lucy sets up a new web server. She allows SSH and HTTPS with UFW, then turns it on.

## Example code

```console
$ sudo ufw allow 22/tcp
Rules updated
Rules updated (v6)
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
```

Allow SSH first, then turn the firewall on. UFW warns before it might cut you off.

## Why it matters

It turns firewall work into a few short lines. So you can close each port the server does not need.

## Common mistake

Turning UFW on before allowing SSH. Your own login is then blocked, and you are locked out.

## Three principles

- **Short rules.** allow, deny, then a port.
- **Off at first.** You turn it on yourself.
- **SSH before enable.** Or you lock yourself out.

## Related terms

- [Firewall](https://learn.benibix.com/term/infrastructure/firewall)
- [nftables](https://learn.benibix.com/term/infrastructure/nftables)
- [iptables](https://learn.benibix.com/term/infrastructure/iptables)
- [sudo](https://learn.benibix.com/term/infrastructure/sudo)
- [Network Port](https://learn.benibix.com/term/infrastructure/port)
- [Fail2ban](https://learn.benibix.com/term/infrastructure/fail2ban)
- [Cloud Firewall](https://learn.benibix.com/term/infrastructure/cloud-firewall)

## Told apart from

- [Cloud Firewall vs UFW](https://learn.benibix.com/compare/cloud-firewall-vs-ufw): People often think the cloud firewall and UFW are one firewall. They sit in two places. A cloud firewall runs in the provider's network, in front of the server, and you set it in a web panel. UFW runs on the server itself. Traffic has to pass both, so a port must be open in each one to work.

## Taught in

- [UFW and Linux Firewalls](https://learn.benibix.com/learn/infrastructure-linux/ufw-and-linux-firewalls): Linux CLI, 10/10
- [Cloud Firewall and Floating IP](https://learn.benibix.com/learn/infrastructure-vps/cloud-firewall-and-floating-ip): VPS, 6/7

![Four stacked layers. At the top, UFW takes a short rule, allow 22. Beside it, the older iptables command takes a long rule. Both feed down into nftables, which holds the rules. At the bottom, the Linux kernel checks every packet against them.](https://learn.benibix.com/diagrams/inf3-linux-firewall.svg)

---

Source: https://learn.benibix.com/term/infrastructure/ufw
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
