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?
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 127.0.0.1, but one line per hostname. Just check the blog post for an example.
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 ------------------------------------------------- #!/bin/bash # Script is used to set the Nameserver Lookup under Max OS X 10.4 with the Console # Script by Stephan Oeste <email@example.com> if [ $# -lt 2 ] ; then echo "Use: $0 <domain> <1.Nameserver> [2.Nameserver]" echo "Example Use: $0 example.tld 220.127.116.11 18.104.22.168" exit 1 fi PSID=$( (scutil | grep PrimaryService | sed -e 's/.*PrimaryService : //')<< EOF open get State:/Network/Global/IPv4 d.show quit EOF ) scutil << EOF open d.init d.add ServerAddresses * $2 $3 d.add DomainName $1 set State:/Network/Service/$PSID/DNS quit EOF ------------------------------------------------- Create the file chmod +x setdns And then use ist with (Example): setdns domain.com 22.214.171.124
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.lionfix.setdns</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/setdns</string> </array> <key>WatchPaths</key> <array> <string>/Library/Preferences/SystemConfiguration</string> </array> </dict> </plist>
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 "127.0.0.1" 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 127.0.0.1, to get rid of hardcoded ips in the script or plist. Would be much appreciated : )