One of the first lines of defence in securing your Pi or Linux is a functioning firewall. In the past, this was often done through complicated and arcane utilities. There is a lot of functionality built into these utilities, iptables being the most popular nowadays, but they require a decent effort on behalf of the user to learn and understand them. Firewall rules are not something you want yourself second-guessing.
To this end, UFW is a considerably easier-to-use alternative. UFW, or Uncomplicated Firewall, is a front-end to iptables.
Its main goal is to make managing your firewall drop-dead simple and to provide an easy-to-use interface.
First you will need to install it on Raspbian:
sudo apt-get install ufw
Then enable it by:
sudo ufw enable
UFW’s defaults are to deny all incoming connections and allow all outgoing connections, once you need to change the
defaults rule, then you can use man page for UFW. The defaults are in most cases all you need.
You can check the status of your firewal rules by typing:
sudo ufw status verbose