How to make changes to Mac /etc/hosts permanent?

On my Mac (running OS 10.6.8), I can edit my hosts file with sudo vi /etc/hosts, but changes I make don't seem to persist through restarts or possibly awaking from sleep mode.

Is there a way to make these changes persist?

Here's a sample change adding an override for www.example.com:

$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0 localhost

1.2.3.4 www.example.com

Update: I am also using Cisco AnyConnect VPN software, and that turned out to be the clue. See Daniel's answer below.

Update 2013-05-20: This behavior was fixed/changed by Cisco in AnyConnect v3.0.5080 (or higher), released in Spring 2013. Release Notes - search for hosts.ac.


Solution 1:

You are using Cisco AnyConnect software, which will overwrite /private/etc/hosts with /private/etc/hosts.ac. Just edit that file instead.

Solution 2:

I've had the same issue. In my case I'm using F5 VPN client. You shouldn't edit /etc/hosts while VPN client is running, because these changes will be erased when you shut down the VPN client. To make your changes permanent, edit /etc/hosts file before you start your VPN client.

Solution 3:

I also had this problem with the Pulse Secure VPN client, which makes a file /etc/pulse-hosts.bak that you should edit too. Editing /etc/hosts before launching Pulse also works.