ufw: program for managing a netfilter firewall
ufw [--force] enable|disable|reload | ufw default allow|deny|reject [incoming|outgoing|routed] | ufw status [verbose|numbered] | ufw [delete] [insert NUM] allow|deny|reject|limit RULE | ufw delete NUM | ufw app list|info
Options you will use
--version- show program's version number and exit
--force- answer yes to the confirmation (enable under ssh, reset, delete NUM)
enable- reloads firewall and enables firewall on boot (ENABLED=yes in /etc/ufw/ufw.conf). Under ssh it asks first.
disable- unloads firewall and disables firewall on boot
reload- reloads firewall
default allow|deny|reject DIRECTION- change the default policy for traffic going DIRECTION: incoming, outgoing or routed (/etc/default/ufw). Existing rules are not migrated.
logging on|off|LEVEL- toggle logging (LOG_KERN: journalctl -k shows the [UFW BLOCK] lines); levels low (default), medium, high, full
reset- disables and resets firewall to installation defaults (the old .rules files are kept with a timestamp)
status [verbose|numbered]- show status of firewall and ufw managed rules; 'Anywhere' = any address
show added- the rules as the commands that added them
allow|deny|reject|limit ARGS- add a rule: simple syntax PORT[/PROTOCOL] or APPNAME, full syntax [proto PROTOCOL] [from ADDRESS [port PORT]] [to ADDRESS [port PORT]] [comment COMMENT]
delete RULE|NUM- deletes the corresponding RULE (NUM from status numbered asks first)
insert NUM RULE- insert the corresponding RULE as rule number NUM
prepend RULE- prepend the corresponding RULE to the top of the ruleset
app list | app info PROFILE- application profiles from /etc/ufw/applications.d (OpenSSH = 22/tcp)
Examples
$ sudo ufw allow from 10.64.0.2 to any port 22 proto tcpSSH only from the admin address - add it BEFORE enable
$ sudo ufw allow from 10.64.0.10 to any port 10250 proto tcpthe kubelet API only from the control plane
$ sudo ufw --force enableturn it on without the ssh question
$ sudo ufw status numberedthe rules with the numbers delete NUM uses
$ sudo ufw limit sshallow, but reject an address that opens 6 or more connections within 30 seconds
Gotchas
- Rules are checked in order, the first match wins; what matches nothing gets the default policy (deny = DROP: the client times out; reject = "Connection refused").
- deny drops silently, reject answers (TCP reset for tcp rules).
- ufw appends its chains to INPUT/OUTPUT/FORWARD; Calico and kube-proxy insert theirs first. NodePorts are DNATed to pods and accepted in FORWARD before ufw runs: ufw does not filter them.
- An established connection (your ssh session, the kubelet's connection to the apiserver) keeps working after enable: the firewall meets it when it reconnects.
Try ufw in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.