The Core Dump

You can’t undo this action

[By Nic Lindh on Friday, 30 September 2011]

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!

Getting started with podcasting

A concise guide to getting started with podcasting, including equipment, editing, mic technique and hosting.

Review: Novels of the Malazan Empire

A worthy inclusion to the Malazan canon and great high fantasy to disappear into in troubled times.

Either America will destroy ignorance or ignorance will destroy the United States

An opinion should be the result of thought, not a substitute for it

Photos from Pacific Beach

The Lindhs visit Pacific Beach and discover a huge bass system and surfers.

Book roundup, part 23

Includes a mea culpa, Hillbilly Elegy, Gulp, The Stars are Legion, and The Kill Society.

Putting new gaskets on the Kamado grill

Nic commits putty knife violence on his grill to replace the gaskets.

Wings of Freedom

Remembering the cost of World War II through airplanes.

The innocent feel guilty, the guilty feel nothing

Patriotism is often an arbitrary veneration of real estate above principles

The pro market, the nerds, and the vision

Apple’s neglect of the pro market is causing a lot of gnashing of teeth in Apple-nerd circles, but it’s true to Apple’s vision.

Never retreat. Never explain. Get it done and let them howl

A wet man does not fear rain

What to expect when you’re expecting a Hackintosh

There is unrest in the Mac community about Apple’s commitment to the platform. Some are turning their eyes to building a Hackintosh to get the kind of computer Apple doesn’t provide. Here’s what it’s like to run a Hackintosh.

Book roundup, part 22

Lots of fiction series in this one. Includes Grunt, 1177 B.C., Louder Than Hell, Smarter Faster Better, The Hanging Tree, Death’s End, Chains of Command, and Who Killed Sherlock Holmes?.

It’s so much easier to suggest solutions when you don't know too much about the problem

Malazan Book of the Fallen

Hey kids, you like epic fantasy? ’Cause I've got some epic fantasy for you.

The car is going digital and that’s a good thing

Car nerds are dealing with some cognitive dissonance as car technology changes.

Review: Kindle Oasis

The Oasis is Amazon’s best e-ink reader to date, but it’s not good enough for the price.

Unhappy the land that is in need of heroes

“Tea, Earl Grey, hot”

Nic buys an Amazon Echo and is indubitably happy with the fantasy star ship in his head.

Mad Max: Fury Road vs Mad Max Trilogy

When the levee breaks

The Occupy movement, the Tea Party, and now Trump. America is angry.

It’s a content blocker, not an ad blocker

The problem isn’t ads. The problem is being stalked like an animal across the internet.

Everything that irritates us about others can lead us to an understanding of ourselves

Review: Synology DS416j

The DS416j is a nice NAS for light home use. Just don’t expect raw power.

Democracy is the theory that the common people know what they want and deserve to get it good and hard

Know what's weird? Day by day, nothing seems to change. But pretty soon, everything's different

Just because nobody complains doesn't mean all parachutes are perfect

(Nerd Note) Moving to GitHub Pages

The Core Dump is moving to GitHub Pages. This is a good thing, most likely.