Pages

07 February, 2014

How to edit the hosts file in Mac OS X



    The hosts file is a plain text file used by an operating system to map hostnames to IP addresses. When connecting to any website, your computer sends out a DNS request to retrieve the IP address of that sites domain name. The hosts file is checked first, before the DNS request is sent out from your system. By listing domains in your hosts file you have control over how they can be loaded (block certain hostsnames, like ad-serving/malicious hosts, or used for web development purposes, i.e. to redirect domains to local addresses).

This post will show you how to edit the hosts file in Mac OS X v10.9.1 (Mavericks) to access Facebook in the countries which block Facebook (China, Vietnam,..).

1. Open the Terminal.app by typing Terminal in the Spotlight search, or go to Applications > Utilities > Terminal:

2. Open the host file by typing below command in the Terminal:
$ sudo nano /private/etc/hosts

Input your password when prompted.
3. The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – local host). Simply append your new mappings underneath the default ones.
In this case, copy and paste following lines into the file hosts:

173.252.110.27 facebook.com 
173.252.110.27 www.facebook.com 
173.252.110.27 www.login.facebook.com 
173.252.110.27 login.facebook.com 
173.252.110.27 apps.facebook.com 
173.252.110.27 graph.facebook.com 
173.252.110.27 register.facebook.com 
173.252.110.27 vi-vn.connect.facebook.com 
173.252.110.27 vi-vn.facebook.com 
173.252.110.27 static.ak.connect.facebook.com 
173.252.110.27 developers.facebook.com 
173.252.110.27 error.facebook.com 
173.252.110.27 channel.facebook.com 
173.252.110.27 register.facebook.com 
173.252.110.27 bigzipfiles.facebook.com 
173.252.110.27 pixel.facebook.com 
173.252.110.27 upload.facebook.com 
173.252.110.27 register.facebook.com 
173.252.110.27 bigzipfiles.facebook.com 
173.252.110.27 pixel.facebook.com 
173.252.110.27 logins.facebook.com 
173.252.110.27 graph.facebook.com 
173.252.110.27 developers.facebook.com 
173.252.110.27 error.facebook.com 
173.252.110.27 register.facebook.com 
173.252.110.27 blog.facebook.com 
173.252.110.27 channel.facebook.com 
173.252.110.27 connect.facebook.com 
173.252.110.27 bigzipfiles.facebook.com

4. When done editing the hosts file, press Control-o to save the file.

Press Enter on the filename prompt, and Control-x to exit the editor.

5. Flush the DNS cache
Once you have modified your hosts file, you can flush your DNS so that you can see your new changes more quickly by using following simple Terminal command:

$ dscacheutil -flushcache


0 comments:

Post a Comment

 
Blogger Templates