how to edit hosts file?

Hi all,

i just tried to edit the /etc/hosts file.


I entered terminal, started vi. No success, no write access.


sudo administrator, no sucess, no write access.


Passwords for root and wheel are unknown, and i self have installed my yosemite.


i tried to do a temporary chmod o+w, no success.



So what, where, when must i do to edit the hosts file?



Thank you!

Greetings from germany

Chris

Mac Pro, OS X Yosemite (10.10.4)

Posted on Jul 8, 2015 9:01 PM

Reply
3 replies

Jul 9, 2015 1:36 AM in response to Christian Stüben

Meanwhile i found several threads here with the same problem.


Some say to move hosts to desktop, edit move back again - my finder doesnt see /etc nor hosts.


Some say that yosemite ignores hosts.


Some say to use specialized host edit apps.


Everything else doesnt work.


My last try has been to sudo as admin or root, but the system told me i am not in the sudoers, which of course can´t be edited too.


What can i do?

Jul 9, 2015 6:01 AM in response to Christian Stüben

There are three levels of user account on a Mac.


  1. 'Ordinary' users
  2. 'Administrator' level users
  3. '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.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how to edit hosts file?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.