UFW basics
UFW (Uncomplicated Firewall) is the default host firewall helper on Ubuntu: it wraps lower-level packet filtering so you can allow or deny traffic with simple commands. This page covers the usual defaults, SSH, and how to inspect or remove rules.
Defaults and enable
Section titled “Defaults and enable”Typical baseline: block unsolicited inbound traffic, allow outbound, allow SSH, then activate the firewall:
sudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw allow sshsudo ufw enableMany installs also ship an OpenSSH application profile (ports and protocols from /etc/ufw/applications.d). Prefer it when it exists:
sudo ufw app listsudo ufw allow OpenSSHYou can still allow the port explicitly if SSH listens on the default port:
sudo ufw allow 22/tcpInspect rules
Section titled “Inspect rules”sudo ufw status verboseNumbered list (needed for deleting by index):
sudo ufw status numberedDelete a rule
Section titled “Delete a rule”By number after ufw status numbered (usually the least error-prone):
sudo ufw delete 3By rule text (must match how the rule was added):
sudo ufw delete allow 3002/tcpDisable UFW
Section titled “Disable UFW”sudo ufw disableSources
Section titled “Sources”- Firewall (Ubuntu Server) — enable/disable, ports, numbered rules, application profiles (accessed 2026-04-06)
- UFW — Ubuntu community documentation — overview and usage notes