Did you know, that UFW usually comes pre-installed on Ubuntu?
You just have to set it up correctly for it to work.
Read More:
https://itsfoss.com/ufw-ubuntu/
Using UFW Firewall in Ubuntu Linux [Beginner's Guide]
Learn the basics of using UFW firewall to secure your Linux system in this beginner's guide.Abhishek Prakash (It's FOSS)