Local Host Entries on OS X Snow Leopard

Today I wanted to setup local host entries on my MacBook. Searching around I found several articles about editing the /private/etc/hosts file to add local domains entries pointing back to my computer. I don't know if it is something that changed with Leopard or Snow Leopard but it just wasn't working for me. Even restarting the computer was a no go.

Using the dscl Utility

With the wonder of Google searching and the generous comments of others I found out about the dscl utility.

Listing Host Entries

To see what is listed for your hosts at any time just run this command:

dscl localhost -readall /Local/Default/Hosts

Adding a New Entry

In this example I am going to have theĀ snow.ftd host point to my 127.0.0.1 IP address:

sudo dscl localhost -create /Local/Default/Hosts/snow.ftd IPAddress 127.0.0.1

You should now be able to ping snow.ftd and have it resolve to your local computer.

Removing an Existing Entry

If you decide you do not want an entry anymore just run this command to remove it:

sudo dscl localhost -delete /Local/Default/Hosts/snow.ftd

Reading the BSD Flat File

It was also noted that you can read the BSD flat file using this command:

dscl localhost -readall /BSD/local/Hosts

Posted on 10 Dec 2009