Tech Tutorial: Hosts File Modification

IT Tips & Guides

How do I view my site on a new server without letting the public see it?

When migrating your website to a new web host, it can be helpful to see the site up on the new server before it goes live. You want to make sure that the site is going to work on the new server without any errors before you start sending traffic over to it. You can copy the site and all your content to the new server, but how do you test the new setup without changing the DNS (and having the whole world see your site on the new server before it’s ready for prime time)?

The best way to do this is to change your personal computer’s hosts file. When you visit a website, your computer has to look up the IP address for that site so that it knows where to go. Before your computer goes out onto the Internet to find the IP address, it will first check its own local hosts file. The hosts file on your computer is a plain text file that contains a map of hostnames to IP addresses.

By changing the hosts file on your personal computer, you can send only your computer to the new server without affecting the live site at all. In essence, you are “tricking” your computer by manually setting the IP address for a particular website and telling it where to go instead.

The process for modifying the hosts file varies depending on what operating system you are running. The following utility has already checked which OS you are running (Mac, Windows or Linux) and has given you instructions on how to change your hosts file. Note that if you are using an older Mac, the instructions are good for OSX 10.5 and higher.

I see you’re running Windows.

Here is what you need to know for your OS:

Editing the hosts file on in Windows is easy. It can all be done in Notepad.

Step 1 – Open a Run prompt

Press the Windows key + ‘R’.

Step 2 – Open the hosts file with Notepad

In your newly opened Run prompt, type the following to have notepad open the system’s hosts file:

notepad c:windowssystem32driversetchosts

Hit ‘OK’ to open the file with Administrative privileges.

Step 3 – Editing the hosts file

Your hosts file will already contain comments (lines that start with the pound ‘#’ symbol), as well as some default hostname entries (e.g. localhost). Simply add in your custom entry for your domain onto its own new line at the bottom. For example:

Step 4 – Save the hosts file

When you are done modifying your hosts file, press Ctrl+S to save the file. Then you can close notepad.

Step 5 – Flush the DNS cache

Typically, you will want to flush the existing DNS cache from your computer so that your host file changes can take effect immediately.

You will need to get to a command prompt. Open ‘Run’ as in Step 1 and type:


Now, inside the command prompt, flush the DNS cache by typing:

ipconfig -flushdns

Click “OK”

Now load your site in your browser and you’ll be hitting the new IP location.

To reverse this process, simply follow the instructions again and remove the line you added to the hosts file.

Important Note: While these directions are reliable, a little knowledge can be a dangerous thing. Do your research and get answers to any questions before editing any program files on your computer. The suits upstairs want me to remind you that we are not responsible any misuse of these instructions.

And as always, if you’re a Emerain customer and have any questions or are unsure of what you are doing, don’t hesitate to open up a support ticket in your customer portal. We’re happy to help.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.