Understanding what a firewall is and how it works:
A firewall is a program that surrounds the interface between a private network and the rest of the big and (usually) bad internet. You can think of the firewall as a gateway. It follows pre-configured rules that allow certain traffic to pass through from the internet to the private network and blocks those that are unwanted and potentially harmful.
To know more, check out this link: https://blog.resellerclub.com/a-step-by-step-guide-on-how-to-configure-firewall-in-linux/
You can watch this video also at the source.