Domains and DNS

Test a website before changing DNS with the hosts file

Reviewed on 3 min read dns desarrollo local

The hosts file lets you tell your computer to use a specific IP for a domain name. You can use it to review a website on the new hosting while other visitors keep reaching the old one.

This saves you from temporarily changing the application's address, but it does not change the public DNS and, on its own, it is no way to test email or external integrations.

Prepare the destination

Add the domain to the hosting and copy the website and its database. Get the correct IP from the service details.

Also check the copy's external connections: a test website can keep sending emails, taking payments or changing a production database. Use those integrations' test mode where appropriate.

Edit the file on your computer

You will need administrator permissions. Save a copy of the file before editing it.

System File
Windows C:\Windows\System32\drivers\etc\hosts
macOS /private/etc/hosts
Linux and other Unix systems /etc/hosts

Add a line with the destination IP followed by the domain and the variants you want to test:

192.0.2.44 ejemplo.com www.ejemplo.com

The IP above is a documentation address: replace it with your hosting's IP and use your real domain. Do not delete the existing entries. On Windows, save the file without adding the .txt extension.

Check that you are seeing the copy

Save the file, restart the browser and open the domain. If the origin still appears, check for duplicate entries, the system cache and any VPN or proxy that resolves names on its own.

A useful check is to place a text file with a unique name in the public folder of the destination, with no private information, and open it from your computer. Delete it when you finish. If you use the browser's developer tools, the request's remote address can also help you identify the server, unless there is a proxy in between.

Do not use the output of nslookup as proof that the hosts file is being applied: that tool queries DNS. A public checker will not see your local change either.

HTTPS and external services

The new server needs a valid certificate for the domain. The hosts file does not issue one or remove the browser's checks. If a warning appears, sort out the certificate's coverage before entering any credentials.

Payment gateways, webhooks and other external services will keep querying the public DNS. To test them you need an environment that is reachable and configured for testing; changing hosts on your computer is not enough.

When you finish

Remove the line you added, save and check access again. It is especially important to do this after the migration so you do not keep forcing an IP that might change.

Before going live, follow the checks after a migration.

You may also find useful

Something wrong or out of date? Tell us and we will review it.