Ok, this is pretty simple really.
First Open up Terminal on your mac, typically found in Applications -> Utilities -> Terminal
From there run
sudo nano /private/etc/hosts
Then it will ask you for your currently logged in Administrator password, this is necessary to auth the access/modifications to the file. Nano editor is pretty self explanatory and I guess if you’ve found this post you probably know what your doing in the hosts file so I won’t go into that. I will say typically you will make a change and hold control then press x to quit, it will ask if you want to commit the changes, press y and thats it.
PS Don’t mess up your hosts file it will make things get broken 😐