Firewall — UFW (ufw.service)

Install:

sudo apt update
sudo apt install ufw

Defaults: deny incoming, allow outgoing, routed traffic disabled. Logging is set to low.

RuleFromPurpose
<SSH_PORT>/tcp<LAN_SUBNET>SSH, LAN only
80/tcp<LAN_SUBNET>nginx default site, LAN only
<NOTES_PORT>/tcp<LAN_SUBNET>Notes site, LAN only
any, on tailscale0anywhere (v4 + v6)Everything arriving over the tailnet

Nothing is reachable from the internet. Remote access goes only through 07 - Tailscale.

Recreate

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from <LAN_SUBNET> to any port <SSH_PORT> proto tcp
sudo ufw allow from <LAN_SUBNET> to any port 80 proto tcp
sudo ufw allow from <LAN_SUBNET> to any port <NOTES_PORT> proto tcp
sudo ufw allow in on tailscale0
sudo ufw enable

Check

sudo ufw status verbose
sudo ufw status numbered   # for deleting rules by number

Warning

Add the SSH rule before ufw enable, or you’ll lock yourself out.

Back: 00 - Overview