If you are working with website development or want to block or redirect access to specific domains, you have probably edited the system file /etc/hosts like me. I have recemtly upgraded to Lion and to my astonishment, I found that the entries in the hosts file is anymore considered. After a lot of checking around, this is what worked for me.
1. If you don’t have the program TextWrangler (Free text editor for Mac), go ahead and install it.
2. Launch Terminal (Go to Applications>>Utilities)
3. in the terminal type sudo edit /private/etc/hosts
4.Enter your password
5. This will launch Textwrangler with the content of the hosts file
6. Ensure that you are having the following format in your hosts file, otherwise you can copy the code shown below and past it there.
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
## localhost ip4
## localhost ip6
7. Go through each of the line and check whether each line is showing Unix (LF) as shown in the below picture and save it.
8. Go to terminal and type ping first.localhost , If you are getting a response as shown below, then it is working fine.