Home·Terminal commands

ufw

Networking

Usage

sudo ufw <allow|deny|status> ...

A friendly wrapper around iptables on Debian and Ubuntu; allow SSH before you `enable` it or you cut the session you are sitting in, and Docker publishes ports straight into iptables where ufw rules do not cover them.

Common flags

FlagMeaning
allow 22/tcpOpen a port; allow OpenSSH uses the named application profile instead.
allow from 10.0.0.0/8 to any port 5432Open a port to one network only.
deny <port>Block it explicitly.
default deny incomingThe usual starting point, set before you enable.
status numberedList the rules with the numbers that delete needs.
delete <n>Remove rule number n.
enable / disableTurn the firewall on or off, persistently.

Examples

sudo ufw allow OpenSSH && sudo ufw enable

Allow SSH first, then switch the firewall on.

sudo ufw status numbered

See what is open and get the rule numbers.

sudo ufw delete 3

Remove the third rule.

When a connection fails, these narrow down how far it got — name not resolving, no route, or a blocked port.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does ufw do?

A friendly wrapper around iptables on Debian and Ubuntu; allow SSH before you `enable` it or you cut the session you are sitting in, and Docker publishes ports straight into iptables where ufw rules do not cover them.

Q. How do I type it?

sudo ufw <allow|deny|status> ... — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man ufw. This command sits under Networking.

Related commands

man page: man ufw