MacOS – osx hosts file not working

hostsmacos

my hosts file looks like this

it should open facebook if you try to open google

173.252.110.27 google.com
##
# 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
::1             localhost
fe80::1%lo0     localhost

also after I added that first line I did:

dscacheutil -flushcache; sudo killall -HUP mDNSResponder

on a OSX 10.8.5 but it doesn't changes anything.

I searched for a while and found different things none helped me.

On this link: Hosts file in OSX Lion not blocking as expected there is a good answer but I don't know how to check which file format I have.

So the question is:
– is there something wrong with my hosts file?
– how do I check which file format I've got

Thank you!

Best Answer

The hosts file does not support wildcards, so you have to map each domain and subdomain, which means, you need to add

173.252.110.27   www.google.com

as well. If you are redirect to a local version of google, eg like www.google.fr, you need to add that as well.

You can edit the host file easily from a terminal window without changing the file format to RichText or similar by running the following command:

$ sudo nano /private/etc/hosts

You need to enter your password. Afterwards, add your changes at the end of the file, not the beginning.

At the end, flush you DNS cache or reboot your mac.