A firewall is a security guard at the door. The guard has a guest list: allowed visitors walk in and everyone else is turned away. The safest rule is to block everything by default and allow only what you need.
ufw is the friendly tool that manages the guest list on Ubuntu. Its name stands for uncomplicated firewall. Mac and Windows have their own built-in firewalls with the same idea.
