2 Replies Latest reply: Jul 27, 2011 3:53 AM by giotti
pilif Level 1 (0 points)

I have just upgraded one of my machines to Lion.


After doing to, I noticed that looking up "localhost" or any of its aliases I created in /etc/hosts took a very long time - likely because it's trying DNS first before it looks at /etc/hosts


After some digging around, I found out that /BSD/Local isn't in the Cache Search policy:


pilif@kosmos ~ % dscacheutil -configuration

DirectoryService Cache search policy:




Unable to get details from the cache node

Unable to get cache configuration information


(incidentally: Do you have an idea what the two errors are?)


Next, I checked the Directory Utility and under "Services", only ActiveDirectory, LDAPv3 and NIS are listed. BSD-Files are gone even though the Directory Uilitity talks about them.


Is /etc/hosts basically gone in Lion or is something wrong with my update?

Mac Pro, Mac OS X (10.7)
  • sjaensch Level 1 (5 points)

    Hey pilif, I had the same problem! I did manage to find a solution. Basically, you need to put every hostname on its own line in the hosts file. So no more multiple host names after, but one line per hostname. Just check the blog post for an example.

  • giotti Level 1 (0 points)

    One possible workaround for this is to use a local lightweight DNS server, like dnsmasq, to answer to local queries and forward anything else upstream.


    I'm using a small script from emzy over at macworld.com to set the order of my DNS servers (I'm on tethering and don't have access to the DNS tab in settings):


    Filename: setdsn
    # Script is used to set the Nameserver Lookup under Max OS X 10.4 with the Console
    # Script by Stephan Oeste <stephan@oeste.de>
    if [ $# -lt 2 ] ; then
    echo "Use: $0 <domain> <1.Nameserver> [2.Nameserver]"
    echo "Example Use: $0 example.tld"
    exit 1
    PSID=$( (scutil | grep PrimaryService | sed -e 's/.*PrimaryService : //')<< EOF
    get State:/Network/Global/IPv4
    scutil << EOF
    d.add ServerAddresses * $2 $3 
    d.add DomainName $1
    set State:/Network/Service/$PSID/DNS
    Create the file
    chmod +x setdns
    And then use ist with (Example): setdns domain.com


    together with a .plist loaded through i.e. "launchctl load -w /Library/LaunchDaemons/setdns.plist", to update the DNS automatically, whenever SystemConfiguration changes (e.g. I reconnect to the internet and get fresh DNS from DHCP). (I've hardcoded my DNS servers into the bash-script, so it's sufficient for me to just launch the script.)


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    <plist version="1.0">


    P.S.: It's easy to install dnsmasq through homebrew (http://mxcl.github.com/homebrew/) just type "brew -vd --use-gcc dnsmasq" to install it and follow directions to copy the config file and launchdaemon in it's place. After that you just need to comment out "listen-address=" and "no-dhcp-interface=" and add "" to those two lines in your /usr/local/etc/dnsmasq.conf. The best thing is that dnsmasq will actually check your /etc/hosts and respects /etc/resolv.conf.


    Hope this helps!


    PS: One could update the script to read the current DNS servers that you get from DHCP and prepend the list with, to get rid of hardcoded ips in the script or plist. Would be much appreciated : )