Ubuntu comes with a default firewall configuration tool called Uncomplicated Firewall (UFW). When you install Ubuntu, UFW is disabled by default. You can check this by opening a new Terminal window (Applications -> Accessories -> Terminal) and executing the following command.
sudo ufw status
If you are new to Ubuntu or Linux you may find it difficult to use Terminal commands all the time. There is answer: GUFW. This is UFW + a GUI (graphical user interface); which means you no longer need to use Terminal and instead to can use the GUI to configure your firewall.
There is a .deb package available for GUFW which makes installation very easy. Just download the latest version from here and double-click on it to start installation. Once the installation is complete, you can open GUFW by going to System -> Administration -> Firewall Configuration.
Note: After you enable the firewall (and configured it the way you like) you can close GUFW. You don’t need to keep GUFW open all the time or add it to the list of startup programs.
A popular alternative to UFW is Firestarter. I’ll be posting about it soon.