Home > Help Center > Website migration > How to use the HOSTS file when migrating a site?

How to use the HOSTS file when migrating a site?

An indispensable part of the work of technical support (mostly for colleagues from night shifts) is to migrate sites from other hosting companies to HostPulse.

In fact, migration is not as complicated as a slow process, and some users are migrating their sites themselves.

In general, the work is limited to copying files to the new hosting, configuring the domain (if not done), creating a new database, importing the archive, and configuring the connection to the new database (if needed).

Whether the client has ordered the new hosting in HostPulse with the site's domain or with another domain name (in this case the site is most likely working with an addon domain), the site's domain is directed via DNS nameservers to the old hosting and we do not have the ability (or it seems so) to test whether site migration is successful.

In this article, we'll show you how to test the site's performance on the new hosting server while the site is still working with visitors from the old hosting.

Creating a record in the hosts file

When purchasing hosting from HostPulse, the client receives an activation email with all necessary data (URL and IP address, usernames, passwords) to access the hosting.

In this email you should find the IP address of the hosting server.

Then you have to open the hosts file of your operating system (OS) and create a record that connects the IP address of the server and the domain name of the site using the following syntax:

12.34.56.78 domain-name.tld

where:

12.34.56.78 is the IP address of the new hosting server;

domain-name.tld is the site's domain name;

How does the hosts file work?

In modern operating systems hosts file is used as an alternative mechanism for connecting hostnames with IP addresses without the participation of the DNS system.

Upon receiving a domain resolving request, the OS first checks if there is a record for that domain in the hosts file, then searches for a record in the local cache on the computer and, if found none, afterwards it sends a DNS request to the ISP, and following a strictly defined procedure it reaches the IP address of the server (where the domain is configured) to which the browser sends the HTTP request.

When we create a correct record in the hosts file, the OS returns the IP address to the browser from the host file record without asking the DNS system.

In this way, our browser sends the HTTP request directly to the new hosting server's IP address where the domain is configured, receives a response from the web server, and loads the site from the new hosting on the monitor screen (or on the display of another device).

Important: In order for the hosts file to work properly, the domain must be configured on the server with the specified IP address. You can not point www.google.com to the IP address of the hosting server. Technically, you can create such a record, but it will obviously not load the www.google.com site from your server.

At the same time, all other site visitors through the DNS system are directed to the old host's IP address and they still are loading the site from it.

This is how we test whether site migration is successful without changing domain's nameservers.

If the site works properly and the migration is done by a technical support operator, the colleague sends an email to the client with the result of the migration and brief information on how they can recreate the record in the hosts file on their own computer in order to test the site's performance from the new hosting server.

When the clients confirm that migration is successful, they change its nameservers or the A record of the domain, and within 48 hours, all requests wll be routed from the DNS to the new hosting.

During this time it is not desirable to stop the site on the old hosting because the requests from Internet networks that refresh their DNS cache at longer intervals will get an error looking for the site on the old server.

This is how any site can be migrated to a new hosting without any downtime.

Still not finding what you're looking for?

Contact our support team with any additional questions or concerns.

Contact support