On a Macintosh you can edit the hosts file using Textedit but it's usually in a protected area so the best thing to do is copy the file to the desktop, edit it and then copy it back here are the steps:

  • Open Finder and in the Finders menu bar select Go > Go to Folder.


  • In the box type /private/etc/hosts
  • A new Finder window will open and you will need to drag the hosts file to the desktop.


  • Double click on the file on the desktop and use Text edit to open.


  • Add the IP and domain that you would like for example 0.0.0.0 example.com, anything with a # in front doesn't get read by the computer.
  • Then save the file and open the terminal by going to Finder > Applications > Utilities > Terminal.
  • Then type ping example.com and press enter and it should resolve to the IP 0.0.0.0 this is for testing.
  • Once editing the hosts file is complete you will need to save the file and then drag it back to it's original location.
  • If the window has gone Go > Go to Folder then type /private/etc/hosts and drag the file into that window. If it asks what to do then select replace.
  • Open Safari or alternative browser and try the website you have entered into your hosts file.
  • If the website doesn't show up and you have cleared your browser cache then use the following command in the terminal:

        Mac OS X Mountain Lion and earlier use this command:

        sudo killall -HUP mDNSResponder

        Mac OS X Mavericks or later use this command:

        dscacheutil -flushcache; sudo killall -HUP mDNSResponder