The Core Dump

It updates the blog, or it gets the hose again.

By Nic Lindh | Friday, 30 September 2011 | FacebookTwitter

Editing the hosts file in Mac OS X 10.7 Lion

If you’re trying to edit your hosts file in Lion, here’s why it’s not working and how to fix it.

I’m posting this in the hope it’ll save somebody else a few minutes of their time.

Apparently Apple has decided to Think Different about the hosts file in Mac OS X Lion. If you want to put in your own entries, they will be politely ignored unless you put them first in the file.

Editing the hosts file allows you to do useful things like preview a site on a production server before flipping the switch on the DNS so you can suss out any errors before the world sees the site, or to access the backend of a CMS on an origin server for updates when the live site is cached by something like Akamai.

To illustrate, here’s the original Mac OS X hosts file, located at /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

If you were to do the standard UNIX thing of appending your own changes at the bottom—which is what you would do if you’ve spent any time around UNIX machines—you’d end up with something like:

## # 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 192.168.1.15 thecoredump.org

But alas, this configuration will in fact not do anything.

The reason is that Apple has apparently decided you must put your own entries at the top. So you must do this instead:

192.168.1.15 thecoredump.org ## # 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

I don’t know why this is. I wasn’t in that meeting. From my Googling around it seems nobody from the documentation team at Apple were in that meeting either.

So if you want to control your hosts file in Mac OS X Lion, you must put your own entries first and it will work like you expect.

You don’t have to flush the cache or anything. Soon as you save the configuration, it goes to work.

Hope this saves somebody on the Internet some time.

« Why I’m all-in on FiveFingers

 »


Enjoy the ten latest posts:

How to install Jekyll on Amazon Linux

Installing Jekyll on an EC2 Amazon Linux AMI is easy. Here are the steps.

Will the Apple Watch be a success?

After wearing the watch for over a month, Nic has thoughts on its future. Spoiler: Depends on how you define success.

Book roundup, part 19

Lots of fantasy and sci-fi in this installment plus a book about sports! Includes Boy on Ice, Difficult Men, Restaurant Man, The Red Line, Cunning Plans, Seveneves, Nemesis Games, Bitter Seeds, The Mechanical, Angles of Attack, and City of Stairs.

Let’s all chill out about the iPad sales numbers

Turns out “it's just a big iPhone” is a stroke of genius.

Tech terms you might be misusing

Some technical terms still confuse people who should know better, like journalists.

Book roundup, part 18

Nic is sad about Terry Pratchett's passing. Includes No Land’s Man, Idiot America, Something Coming Through, The Burning Room, Foxglove Summer, and The Dark Defiles.

BlueBuds X and Jabra Revo Bluetooth headsets review

Bluetooth headsets are maturing rapidly and these are both good in their own ways and for different purposes.

Naked root domain with Amazon S3 without using Route 53

How to host a static site on Amazon S3 with an apex domain without using Amazon’s Route 53.

Say hello to Brimful Podcast

Nic finally launches his own podcast wherein he explains technology to humans.

Another shot of wet socks against net neutrality

The Republic prints another sad editorial about net neutrality. Nic’s regard couldn’t be any lower.