Run the following commands in a terminal window:
# update software repositories
sudo apt update
# install ufw
sudo apt install ufw -y
# enable ufw
sudo ufw enable
# output the ufw status
sudo ufw status
# add some default firewall rules
sudo ufw default deny incoming
sudo ufw default allow outgoing
# if a webserver is running, allow the incoming traffic
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# to allow incoming ssh connections, open port 22
sudo ufw allow 22/tcp
# output the ufw status
sudo ufw status
# to install a graphical user interface for ufw, install gufw
sudo apt install gufw -y