Posted by Dan Delaney | 30th Oct 2011
UPDATE: I have also had this re-occur with macOS Sierra. Using this fix still works.
After upgrading to OSX Lion 10.7.2, I found that the hosts file no longer worked as expected. I have several entries in my hosts file for local development domains of my sites, i.e; I use 'itnonsense.lcl' as an alias for this site.
After updating Lion, I was getting DNS resolution errors which meant that without workarounds I couldn't get my local domains to work correctly - until now. Fortunately, it is quite an easy fix.
Using a text editor such as TextWrangler, open the hosts file using 'sudo', for example:
sudo /Applications/TextWrangler.app/Contents/MacOS/TextWrangler /etc/hosts
The fix is to ensure that the new lines are set to Line Feed format, rather than any other format (e.g. carriage return). In TextWrangler this is Unix LF.
In addition, ensure all your custom entries are before the 'fe80::%1%lo0 localhost' line and save the file.
Example (working) file:
## # 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 # Custom Entries 127.0.0.1 itnonsense.lcl 127.0.0.1 google.com 127.0.0.1 apple.com # Standard Entries ::1 localhost fe80::%1%lo0 localhost