How to update your host file on your Mac OS

If you are making a new website it is really handy to be able to see and work on that website before it is live to the world but how do you do that? 

Well the first thing is to setup your hosting.  When you setup your hosting account you will get sent an email which tells you the IP address for your webhosting.  This part is important - note this down.

The next thing to do is to follow the below instructions to update the host file on your Mac, essentially what this does is tells your computer to go to the new hosting when you type the url into a browser, but everyone else in the world will go to the old website.

This allows you to work on your new website while the old one is live, this is very handy if it takes you a while to set everything up.

Mac OS Host File Update Instructions

Editing the hosts file in Mac OS X – Leopard, is a fairly straight forward  task, especially if you are familiar with the terminal.

Step 1 – Open the Terminal.app

Either by start typing Terminal on the Spotlight, or by going into Applications -> Utilities -> Terminal.

Step 2 – Open the hosts file

Open the hosts by typing on the Terminal that you have just opened:

$ sudo nano /private/etc/hosts

Type your user password when prompted.

Step 3 – Edit the hosts file

The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – localhost).
Simply append your new mappings underneath the default ones. Or edit one of the default values if you know what you are doing!
You can navigate the file using the arrow keys.

Put the IP Address first then the url so it looks something like the following

74.125.237.159    www.google.co.nz
74.125.237.159    google.co.nz

But put the ip address for your new hosting and put your domain name instead of Googles domain name.  Also, I may be a good idea to put both www.google.co.nz and google.co.nz as by default some cms's exclude the www.

Step 4 – Save the hosts file

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.

Step 5 – Flush the DNS cache

On Leopard you can issue a simple Terminal command to flush the DNS cache, and have your host file changes to take immediate effect:

$ dscacheutil -flushcache

You can now view and update your new website in your browser.


  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to setup email accounts with CyberHub's webhosting

The first thing is to login to your CyberHub webhosting account using your username and password....

How to setup Outlook with CyberHub's webhosting email

If you are familar with how to setup Outlook with POP email use the settings below otherwise...

How to setup iPhone with CyberHub's webhosting email

If you are familar with how to setup your iPhone with POP email then use the settings below...

How to setup free webhosting with CyberHub

It is very easy to setup free webhosting with CyberHub.Go to CyberHub's Linux Webhosting Page...

How to update your host file on your PC

If you are making a new website it is really handy to be able to see and work on that website...