/etc/hosts file is reverting to a previous state in OS X?!?

Problem: I make changes to my /etc/hosts file — but they don’t seem to “stick”. They take affect, but after some time (hours, a day) the changes I made are lost.

Solution: When changing the /etc/hosts file, make sure you are NOT connected to the VPN (at least if you are using Network Connect by Juniper Networks.)

Story: For a long time I have noticed that when I make changes to my /etc/hosts file it reverts back to a old state at the end of the day (or eventually). It has been very annoying as you can imagine. I have been keeping all my entries in a separate file & add them to my hosts file when I need them. Ugg. I got a clue via aardvark that it may be VPN related.

It turns out that when I disconnect from the VPN the hosts file reverts to the state it was in before I connected to VPN. Ahh…. but If I make changes before being connected to VPN, then they stick.  I would connect to VPN, make changes to /etc/hosts, then eventually time out or disconnect from VPN… poof! Changes are gone & the next day begins.

This was not obvious to me because 99% of the changes I make to the /etc/hosts file require the VPN to work to begin with! In addition, I mostly work remote — so it is rare that I will be in the office (not connected to VPN) and make changes to my hosts file.

Now I know to make changes to my /etc/hosts file before connecting to my VPN 🙂