LAN protection

I have a QNAP NAS connected to the LAN that was attacked and the files were encrypted. As I have backup of my pictures and music, I just formatted the disks. Now that I copied the files to the NAS again, I would like to know how to protect them. Is it possible to install a firewall at LAN level, maybe at the router? What should I do to avoid a similar situation? Thank you for any help!

https://www.qnap.com/en/how-to/faq/article/what-is-the-best-practice-for-enhancing-nas-security