Skip to content

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.

Typical baseline: block unsolicited inbound traffic, allow outbound, allow SSH, then activate the firewall:

Terminal window
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw enable

Many installs also ship an OpenSSH application profile (ports and protocols from /etc/ufw/applications.d). Prefer it when it exists:

Terminal window
sudo ufw app list
sudo ufw allow OpenSSH

You can still allow the port explicitly if SSH listens on the default port:

Terminal window
sudo ufw allow 22/tcp
Terminal window
sudo ufw status verbose

Numbered list (needed for deleting by index):

Terminal window
sudo ufw status numbered

By number after ufw status numbered (usually the least error-prone):

Terminal window
sudo ufw delete 3

By rule text (must match how the rule was added):

Terminal window
sudo ufw delete allow 3002/tcp
Terminal window
sudo ufw disable