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 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. – local host). Simply append your new mappings underneath the default ones.
In this case, copy and paste following lines into the file hosts:

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


Post a Comment

Blogger Templates