:space
:vision
do not step out
:wire
twitter.com/mikeysan
nuke and pave
27/May/2005 | 15:55

Who Moved My Hosts File?

By now, some of you probably know that the installer for Mac OS X 10.4 Tiger Super Turbo Championship Edition will completely overwrite the /etc/hosts file, even when you configure the installer to use the "Preserve Users and Network Settings" ninjitsu that is otherwise quite awesome.

Can someone tell me why "Preserve Network Settings" doesn't include the hosts file? There's no reason that the installer option shouldn't include other networking configuration the user has done in addition to simple network locations. Since I don't want this to turn into a half-balled rant, let's back up:

Theory:

You, Mr Pretty Good Programmer, need to make sure that there are three important entries in /etc/hosts before restarting the machine after install:

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

To ensure the client's hosts file has these lines, you have your installer write a clean hosts file, regardless of preservation settings. You've guaranteed yourself—and in doing so, your users as well—a perfectly working, painless installation procedure.

Well, you've got the "perfectly working" part down, anyway.

Do Not Pass GO, Do Not Collect $200

Okay, so your client base is pretty diverse. Grandmothers, high school English teachers, musicians, celebrity bloggers, and some pretty sharp scientists are all using your operating system, and they're all doing different things with it. Why, right down the street, Ack uses your OS every day. Ack is a typical network/systems admin. At any given moment, Ack's PowerBook could be connected to two or three different computers, browsing the Interweb, or waiting for the results of his latest nmap query.

Needless to say, Ack's hosts file is pretty decked-out. He's got a dozen different internal servers' IPs mapped to easy-to-remember hostnames like "suckbox" and "helldemon". (Ack's kinda bitter from an Oracle install that went awry once long ago. Don't ask.) His home ISP is pretty bad, so he's got a few frequently used sites' domain names plugged in there somewhere. In addition to all of this, one day Ack got fed up with seeing so many damned ad banners left and right, so he summoned some John Woo action and blocked hundreds and hundreds of advertisers' servers with a little help from everythingisnt.com.

Boy, was Ack pissed when he upgraded to Tiger.

Profanity Is a Stress Reliever

"Why did they have to overwrite my !&#^@*# hosts file?" Ack uses the word "they" because he sees you as having hosed his hosts file, not a faceless installer script. He uses the word "!&#^@*#" because he drinks too much coffee.

Ack goes and looks through his backups and with some head and diff action, he realizes that there was no change to the stock hosts file from Panther to Tiger. And indeed, the first nine lines of his hosts file matched the original file and the replacement file from the Tiger installer.

Even assuming Ack didn't do the Bright Thing™ and add his customizations to the bottom of the file, and peppered them all around the original three entries, Ack knows that the three lines themselves should always be identical to their original state, even if they're not contiguous. Grep, he figures, should have been able to find the entries. If they all had been there, the installer could have left the file alone; if one had been missing, it (or all three entries) could've been written back to the top of the file.

"All it did was erase all of my customizations, essentially!" Ack yells into his monitor. He's not too pissed, because he's got backups, but he, like many others, considers /etc/hosts to be part of his "network settings".

So if all it would have taken was a little bit of shell scripting to see if the hosts file still has the original three entries it needs, why just nuke it down?

Rule:

If you can reasonably avoid forcing your users to retrieve data from backups, you do.

Theory:

Ack could probably use a vacation, anyway.

1 Comments:

This has happend to me a few times in the past. I think something related hozed my Apache config file too. My old site (now dead-ish) used PHP and when a big update came out it obliterated PHP settings in Apache's config file.

P.S. Great shot of our bathroom :)

posted by Hippieman on May 27, 2005 at 16:41