How can I lock files with specific passwords on mac, ideally through terminal?

I want to lock my /etc/hosts file so that you need a password in order to write. I know you can encrypt files with Disk Utility, but in this case the file needs to be read by the computer and the path/extension cannot change. I don’t just want to lock the contents, I want to lock this file very specifically.

If I run sudo vim /etc/hosts I need to type my login password but can then do whatever I want.

I want a solution where if I run sudo vim /etc/hosts, I must type a customized/specific password to write to the file.