Preview site ahead of DNS change using Hosts file

To test your website with your own domain name before DNS propagation has completed, you can use your local computer's HOSTS file. Your computer will use the entries in your HOSTS file before it looks up the DNS information for your domain. This article contains instructions for editing the HOSTS file on Windows 95/98/Me/2000/XP/2003/Vista/7, and Apple's Mac OS X.

When you are finished testing, remember to remove the custom lines that you added.

Windows

Locate the HOSTS file on your computer. Typically it is in one of the following locations:

Windows NT/2000/XP/2003/Vista/7 - C:\windows\system32\drivers\etc\hosts
Windows 95/98/Me - C:\windows\hosts

Open this file with a text editor such as Notepad or Wordpad.

Right-click on Notepad and select the option to Run as Administrator - otherwise you may not be able to open this file.

Then, open the file. Consider performing a "Save As" so you have an original copy of the file that you can restore later. You will see two columns of information, the first containing IP addresses and the second containing host names. By default, a windows hosts file should be similar to the following:

hosts
127.0.0.1 localhost

You can add additional lines to this file that will point requests for a particular domain to your new server's IP address. Example:

hosts
127.0.0.1 localhost
89.145.89.80 example.com
89.145.89.80 www.example.com

Save your changes.

Restart any currently open browsers. You may also want to flush your DNS cache. In Windows XP, go to Start, and then Run, then type "cmd" and hit enter. Type the following:

ipconfig /flushdns

Visit your new site using http://example.com/ or http://www.example.com/

Mac OS X

Open Terminal, which is in Applications, then the Utilities folder.
You may want to first make a backup copy of your existing hosts file:

sudo cp /private/etc/hosts /private/etc/hosts-orig

Enter your user password at the prompt.

Type the following command to edit your hosts file:

sudo vi /private/etc/hosts

Enter your user password at the prompt.

You will see a file with contents similar to the following:
hosts

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##

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

Add your domain and IP address to the bottom of the file. For example:

##

# Host Database

#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
89.145.89.80 example.com
89.145.89.80 www.example.com

vi tip: Press "i" to enter "insert mode" so you can type and copy/paste. Press "Esc" to exit "insert mode" when you are done modifying the file. Type ":wq" to save and quit.

You may also need to grant yourself sudo priveleges, if you got a permission error in Step 2. In your "Help" menu, search for "root" and select the instructions for "Enabling the root user." Follow these.

Restart any currently open browsers. You may also want to flush your DNS cache:

dscacheutil -flushcache

Visit your new site using http://example.com/ or http://www.example.com/

  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

How do I upgrade my Hosting package?

Upgrades: You can upgrade your hosting package at any time in your My Nativespace area...

How do I Downgrade my Hosting package?

You can downgrade your hosting package at any time, so long as your disk space and bandwidth...

How do I order extra Disk Space, Bandwidth or an IP Address?

You can purchase addons for your hosting package from your client area...

Transfer website from another host

In order to minimise the chance of any possible disruption to your service whilst switching from...

How to serve main Domain Name from a subdirectory?

Assumptions: Your domain name is → MyDomain.com You have a cPanel (hosting)account with this...