There are three levels of user account on a Mac.
- 'Ordinary' users
- 'Administrator' level users
- 'root' aka. SuperUser
The file /etc/hosts is owned by 'root' and needs root level access to edit it. Trying to edit it as a normal user will clearly not work, nor will editing it as an 'Administrator' level user by doing the following.
Login to Mac as ordinary user
Open Terminal
su administrator
vi /etc/hosts
The above does not work because you are still only working in Terminal as an administrator level user and not as 'root'.
The following should work
Open Terminal
sudo vi /etc/hosts
or if you are logged in to the Mac as an ordinary user the following will get round your user level login not being in the sudoers file
Open Terminal
su administrator
sudo vi /etc/hosts
The sudo command runs the rest of that line as root level permissions. It will ask for the administrator password, but will run as root.
If you don't know the user name and password for an administrator level user then you should not be trying this.