I had to modify local hosts file on OSX many times and itβs not just about edit and save because it requires few more things before and after.
To properly edit the hosts file on OSX, first you need to get super user access, then to remove protection from hosts file with chflags, edit hosts file and save, flush DNS cache (optional), and to set back the hosts file as protected (otherwise it will not work).
sudo su β chflags nouchg /private/etc/hosts sudo nano /private/etc/hosts sudo killall -HUP mDNSResponder chflags uchg /private/etc/hosts