A great simple firewall for Ubuntu is ufw. It might be running on your system right now:
ufw status [verbose]
…will tell you whether it's running or not.
It's very easy to use. Here's a sample of some of the commands I used to configure the firewall.
…that's how you turn it on. And, it stays on, even after reboot. But, you won't be able to access your system unless you open some ports first. That's done by setting up applications. Applications are just descriptions stored in a text file that lives in /etc/ufw/applications.d/. Ubuntu comes with a few preconfigured applications as an example, so if you want to open more ports, then set up your own applications.
To list the applications:
ufw app list
To activate an application:
ufw allow Apache