Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In order to do web development on my local machine, I use the /etc/hosts file to define hosts that point back to to which I have Apache serve up via VirtualHosts. This works great, except that now it seems that Lion resets my /etc/hosts file every so often.

Has anyone else experienced this? Is there any way to keep this from happening?

I never had this problem in Snow Leopard.

share|improve this question
do you have file ? or any other copies of hosts file ? – user570144 Nov 25 '11 at 1:51
@user570144 Seems you were right. – Daniel Beck Jan 17 '12 at 20:50
Yes. user570144 was right. Sorry I didn't see the comment here. – Jimmy Z Jan 18 '12 at 23:24
I do experience this problem in Snow Leopard 10.6.8 – bzx May 18 '12 at 12:34
up vote 36 down vote accepted

I just discovered what is resetting my /etc/hosts file. It the Cisco AnyConnect VPN Client. Any time I would connect to my organization's VPN, it was resetting the hosts file to a default. I so rarely connect to the VPN, that it made the problem seem intermittent.

If you use Cisco's AnyConnect VPN Client, please be aware that it will reset your hosts file to the contents of the following: /etc/

To solve the problem, make your hosts changes in both the /etc/hosts and the /etc/ file.

I got the hint from MacWorld.

share|improve this answer
Same experience, but guessing it's from Cisco Unified Personal Communicator (cupcake). SURE HOPE THIS FIXES IT. I don't use the VPN enough to match when this happens to me. Also this only happens when I restart. – doublejosh May 7 '12 at 19:15
Would love to read an explanation from Cisco as to why it does this – matt b Feb 5 '13 at 16:23
This behavior was fixed/changed in AnyConnect v3.0.5080 (or higher), released in Spring 2013. Release Notes - search for – BrianC May 20 '13 at 18:24

Directory Services (NetInfo in Tiger and earlier) has its own static hosts map, which will be used by the address resolver before /etc/hosts. These can be manipulated through Directory Utility or dscl.

dscl localhost -create /Local/Default/Hosts/ IPAddress
dscl localhost -create /Local/Default/Hosts/ IPAddress
dscl localhost -create /Local/Default/Hosts/ IPAddress
dscl localhost -create /Local/Default/Hosts/ IPAddress
share|improve this answer

I haven't seen this behavior on Lion and I have a custom /etc/hosts.

Is the whole file reverting, or the top few lines for common entries like

It might be possible that certain operating system actions re-apply the top few "standard" /etc/host lines, so I might try adding lines, instead of editing those...

Mine looks something like this and has never magically changed:

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost

# route some web requests locally
share|improve this answer
For some reason, adding additional address lines weren't working back when I was first updating the /etc/hosts after making the migration to a new Lion machine. So, I was adding an entry after the localhost on the top line. It's working now, so I added new lines and I'll watch to see if it resets again. I must have been doing something wrong originally. I'll mark this as resolving my problem after I can verify with a bit more time. Thanks! – Jimmy Z Nov 7 '11 at 21:55
I listed the domain mapping below the bottom default localhost, and it was reset this morning. – Jimmy Z Nov 14 '11 at 16:20

I witnessed the same problem as Jimmy Z. Really frustrating, especially since I have numerous custom hosts. It wasn't until the 3rd or 4th occurrence that I realized it was always happening after a reboot.

I finally stumbled upon this blog post which suggested to delete and recreate the hosts file. I followed the suggestions, rebooted and was relieved to find /etc/hosts in the pre-boot state. Here's a recap of what I did.

  1. opened /etc/hosts can copied the contents
  2. $> sudo rm /etc/hosts{,.ac}
  3. $> sudo touch /etc/hosts
  4. opened /etc/hosts and pasted in the contents
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .