Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to edit my hosts file on Mac OS X Lion 10.7.4. I've tried all the Terminal trickery I can, but I always get "Operation not permitted" when attempting to modify the file. I've tried:

sudo chmod 777 /etc/hosts
sudo chmod nouchg /etc/hosts
sudo cp ~/hosts /etc/hosts

All fail with "operation not permitted" messages. Here's the output of ls -lO@e /etc/hosts:

-rw-r--r--  1 root  wheel  uappnd,nodump,opaque 2073 Sep 22  2010 /etc/hosts

Unfortunately, I have no idea how to read most of that. Any tips?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

The user append-only flag is set. Run

sudo chflags nouappnd /etc/hosts

and you should be able to edit and save the file as the superuser.

share|improve this answer
1  
And for that matter, why are the nodump and opaque flags set? –  Gordon Davisson Jul 21 '12 at 3:47

Do not change any permissions to hosts.

To use vi to edit the file:

sudo vi /etc/hosts

Enter your password and you can edit and save.

share|improve this answer
    
That won't work. The uappend flag only allows the file to be appended to. Even root cannot overwrite the file when this flag is set. –  Kyle Jones Jul 21 '12 at 18:19
    
It works with 10.6.8. Is the uappend flag new to 10.7? –  broomdodger Jul 22 '12 at 6:18
    
No, those file flags are very old. They were inherited from FreeBSD, which inherited them from 4.4BSD. Probably the earliest Mac OS X releases had them, certainly 10.4-10.7 do. The question is why uappend was set on /etc/hosts. It isn't set on my 10.7.4 Lion (Server) installation. Neither it nor opaque nor nodump make sense there, except perhaps in a virtual machine context. –  Kyle Jones Jul 22 '12 at 17:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.