How to test website using domain name before DNS is propagated?
Download:
If your domain is not registered or your domain is still pointing to old hosting server, you can still test your new website using your domain name on the new server. The way to do this is to make your computer resolve the DNS for your domain to the new server instead of asking domain’s DNS server to resolve it for you.
This is how it works. Your computer has a “hosts” file that contains domain and IP address mapping. When your browser loads up the website, it first checks this local hosts file to resolve the domain to its IP address. If it cannot find it in that file then it goes out to the proper name servers to resolve it. Since the actual name servers for that domain either are not setup or point the domain to old hosting server, we can use hosts file to have the computer resolve the domain locally.
On Windows XP/Vista/7/8, this file is located at this path on your computer:
c:\windows\system32\drivers\etc\hosts and on Mac this file is located at /private/etc/hosts
On Windows, first you need to open Notepad by right clicking and selecting Run As Administrator. This is important otherwise you cannot edit the file. Then you open the hosts file from File > Open menu by browsing to that path. You will need to change the option on File Open Dialog from “Text Documents (*.txt)” to “All Files (*.*)”. This option is located towards the lower-right corner. This will allow you to see the “hosts” file listed in the dialog box that does not have any extension. It is just “hosts” file and not “hosts.txt”.
Once the file is opened, you can see it has simple one line entries with IP address and domain name. All lines that start with # are comments and are ignored by the computer. Add two new lines with your server IP address where the domain is hosted and is setup to use that IP.
IP_ADDRESS yourdomain.com
IP_ADDRESS www.yourdomain.com
Save this file and restart your browser (Chrome, Firefox, etc.). Now when you access your website, it will resolve locally and go to your new server. Test the website and once you are done, remove or comment out those lines by adding # before IP address. Save the file and restart browser. Now when you load the website, it will go to old server or however the actual name servers of the domain are setup.
This is a very simple yet powerful technique to test your website.
If you are on a Mac the file is located at /private/etc/hosts
Open terminal. Go to the that folder /private/etc/ and use nano editor to open the hosts file:
sudo nano hosts
Use the same exact format as listed above for hosts file and add two lines i.e.
IP_ADDRESS yourdomain.com
IP_ADDRESS www.yourdomain.com
Press Ctrl+o and accept changes to save the file. Press Ctrl+x to exit.
Note: To test that your local hosts file is indeed resolving to new IP, you can go to Command Prompt on Windows or Terminal on Mac and issue this command:
ping yourdomain.com
This will show you the IP address in result and response from the remote server.
When done testing, make sure to undo the changes in hosts file. If you face any problem, please contact support for further assistance.