_ap_ufes{"success":true,"siteUrl":"www.callingallgeeks.org","urls":{"Home":"http://www.callingallgeeks.org","Category":"http://www.callingallgeeks.org/category/android/","Archive":"http://www.callingallgeeks.org/2014/10/","Post":"http://www.callingallgeeks.org/mobogenie-alternate-android-google-play-marketplace/","Page":"http://www.callingallgeeks.org/about/whiz-techy/","Nav_menu_item":"http://www.callingallgeeks.org/113112/","Wpcf7_contact_form":"http://www.callingallgeeks.org/?post_type=wpcf7_contact_form&p=36641","Feedback":"http://www.callingallgeeks.org/?post_type=feedback&p=113523"}}_ap_ufee

CallingAllGeeks

How to Edit Hosts File in Mac OS X using the Terminal

How to Edit Hosts File in Mac OS X using the Terminal

Your mac has a hosts file which contains a list of IP and domain addresses. Whenever a URL is accessed on the Mac using the browser or other apps, the system first checks for entries in the hosts file and fetches the IP address if found. So one can edit Mac’s hosts file to block specific domains like those sending ads or malware. It can be used to block unsafe sites on a Mac or even help downgrade iPhones to older firmware.

Where is Mac’s Hosts File Located:

You can find the “hosts” file in private>etc folder on the active startup partition. In order to edit it and save changes you need the rights of a root user, as this is an important system file.

Default Content of Hosts File in Mac OS X:

There are four very important entries in the hosts file which should not be messed with. In case you did change something you shouldn’t have or wonder which entries existed from the beginning, here are the default contents:

127.0.0.1          localhost


255.255.255.255    broadcasthost
::1                localhost
fe80::1%lo0        localhost

As you can see for yourself, the entry on the left side is the IP address for the domain mentioned on the right hand side.

How to Edit Mac’s Hosts File:

Screen shot 2011 03 14 at 4 06 43 AM

  • Launch Terminal from Applications > Utilities or Spotlight(Command + Space)
  • Open hosts file by typing the command sudo nano /private/etc/hosts and press enter
  • Add or delete entries as required. IP address on the left and domain name to the right, under the four existing entries.
  • Save the hots file by pressing control+O followed by enter. Press control + X to exit the editor.

Now that you’ve learnt how to edit the hosts file let’s see how to apply it in a useful situation.

Blocking Access to a Website in Mac OS X:

Suppose I want to stop access to a website called www.notforkids.com. Here’s the line that needs to be added at the end of the hosts file.

127.0.0.1       notforkids.com

Trick Mac by Redirecting to Another Site:

You might have come across this method while downgrading iPhone firmware. Since, Apple does not officially allow downgrading devices to older iOS firmware developers add the following line to the hosts file to trick iTunes into believing it is talking to Apple’s servers(gs.apple.com) while it is in fact talking to Saurik’s servers.

74.208.10.249       gs.apple.com

That’s all for this tutorial. If you face any difficulties, feel free to ask.

Article by Rajat

Rajat has written 231 articles.

If you like This post, you can follow shoutmetech on Twitter. Subscribe to shoutmetech feed via RSS or EMAIL to receive instant updates.


{ 2 comments… add one }

  • Dave April 13, 2011, 11:16 pm

    I cannot find the host files on my mac,nothing comes up?? I Had jb 4.1 and then i went to 4.3.1 and cannot get a jb for this os that works. Can you help me out.I did save my shsh.

  • Lee September 23, 2011, 4:12 am

    Hi,

    I’ve been struggling with altering my hosts file for over a week now and tried everything I can find on the web, but can’t seem to be able to do it.

    I’ve tried the sudo nano method, but when I come to save I get a “Operation not permitted” error.

    Can you help at all?

Leave a Comment