For reference: https://www.webservertalk.com/ubuntu-firewall-how-to-configure-ufw/.
Run the following:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22 # ⚠️ Replace by your actual SSH port (22 by default) — otherwise, SSH access will be lost after reboot!