# UFW (Uncomplicated Firewall)

> How UFW manages the Linux firewall on Ubuntu, how to allow SSH before enabling it, and how to list and delete rules.

UFW (Uncomplicated Firewall) is the default firewall front end on Ubuntu. It manages the kernel's packet filter through short commands such as 'ufw allow 22/tcp'. It is installed but inactive by default, and the default policy denies incoming and allows outgoing connections.

## Rules

'ufw allow 443/tcp' opens a port, 'ufw deny' blocks one, and 'ufw limit ssh' allows SSH but blocks addresses that connect too often. 'ufw allow from 203.0.113.5 to any port 22' allows one address only. Application profiles, such as 'OpenSSH', are listed with 'ufw app list'.

## Status and deleting

'ufw status verbose' shows the policy and rules; 'ufw status numbered' numbers the rules so that 'ufw delete <number>' can remove one.

## Docker and UFW

Docker writes its own iptables rules for published container ports, which are processed before UFW's rules. A port published with docker run -p can therefore be reachable even when UFW does not allow it.

## How to turn UFW on without locking yourself out

1. Allow SSH first: sudo ufw allow OpenSSH
2. Allow the other services you need, for example: sudo ufw allow 443/tcp
3. Turn the firewall on: sudo ufw enable
4. Check the result: sudo ufw status verbose

## Cautions

- Enabling UFW over SSH without an SSH rule cuts your connection.
- Ports published by Docker containers can bypass UFW rules.

## Sources

1. [ufw(8) manual page (Ubuntu)](https://manpages.ubuntu.com/manpages/noble/man8/ufw.8.html)
2. [Firewalls (Ubuntu Server documentation)](https://ubuntu.com/server/docs/how-to/security/firewalls/)

Last reviewed: 2026-10-08
URL: https://wiki.raincleaner.eu/linux/ufw
