How to preview your website before spread your DNS

When you are migrating a web page to a new server, sooner or later you will face the need to test your web in the new server before spread out your DNS to be sure that all is running fine before go live.

Plesk panell offer you differents solutions but the easiest way is just to change your host file in your local computer.

How it works?

When you enter a domain address in your favourite browser like Google Chrome, Firefox or Safari, the OS looks inside a configuration file to know where to find the translation between domain name you hav writted  and IP number that the domain is pointing to.  This configuration file is call ‘hosts’ file.

In Linux systems the hosts file is placed on /etc/hosts.  Below you can see a normal hosts file coming from Ubuntu 15.10 with no extra content:

host

Let’s trick the hosts file a little!

sudo /etc/hosts

and add a line with IP and domain, for instance:

127.0.0.1                braludo.com

save the changes and point your browser to braludo.com

If you have a server up in your local machine you will see your local home page or an error message showing that the page is not available.

That is all.  You only need to point the domain you have transfered to the new server with the IP address of the new server.

There are lot of web app showing IP number associated to a domain in the web but the results showed are the ones related to the DNS servers spread out around internet.  Imagine that you have cloned your web page in a new server.  When you point your browser to your domain your OS will look inside the hosts file and then send a request to the server pointed by the IP addres in the host file.  Now your browser is showing your web page but how to know which one is the showed one? Using a web app to see the IP number will show you the old server IP but the fact is that the browser is pointing to the new server.  There is a trick to know which IP a domain is pointing to in your local computer if you use Google Chrome.

Point the browser to:

chrome://net-internal/#dns

and you will see the following screen:

host1_cacheç

 

From here you can check which one is the real IP your browser is pointing to and also you are able to clear the DNS cache.

And that is all.

Do not forget to change the /etc/hosts file back when DNS propagation will be finished!

One thought on “How to preview your website before spread your DNS

Leave a Reply

Your email address will not be published. Required fields are marked *