In this post, we will show you the best way that we have found so far (with almost 20 years of experience) to open and test your website at your new hosting provider, while for everyone else your website still loads from your old hosting provider.

We know that changing hosting providers can be challenging if you do not want any downtime on your website. Things get even harder if you are using a content management system (CMS) or website software (i.e. WordPress) that stores most of the content based on the domain name/URL, and all that content is stored in a database.

Moving the website files and database from your old host to your new host may not be enough to get your website working properly as most hosting providers use different hardware, services, and settings. That is why, we always recommend that our customers test their website/s after we migrate the website/s to our servers and before the domain/s are pointed to our servers. The testing is done by tricking your computer into looking up your website from the new hosting provider instead of the global Domain Name System.

In general, the Domain Name System (DNS) stores various information about domain names on the Internet; most importantly the mapping of domain names to IP addresses. This allows you and everyone else to access websites by entering a domain name in the browser instead of a hard-to-remember IP address.

Every computer has a local DNS that is stored in a system file called “hosts”. The “hosts” file allows you to override the global DNS mapping on a local level and force your computer to resolve a domain name to another location. This is very handy if you are switching hosting providers or servers as you can access and test your website at the new location, while the website will continue to work from its original location for everyone else.


We will divide this post into three parts:

Find and open the “hosts” file

To access the “hosts” file, you will need to perform different actions depending on your computer’s operating system. That is why, we will provide step-by-step instructions for the most popular operating systems:

To open the “hosts” file on Windows 10 and Windows 8, you can refer to our follow-along video or run through the steps listed below:

1. Open the Windows Start Menu by clicking on the Windows Start icon on the left end of the Taskbar, or by pressing the Windows key on your keyboard.

2. Type “notepad” to search for the Notepad application.

3. Right-click on the Notepad application, and select “Run as administrator“.

Note: A “Do you want to allow this app to make changes to your device?” pop-up may appear, where you will need to click “Yes“.

4. Open the “hosts” file in Notepad – click on “Open” from the “File” menu, enter

%WinDir%\System32\drivers\etc\hosts

in the “File name” field, and click on the “Open” button.

5. Adding new custom mappings to the “hosts” file is the same across all platforms. You can find detailed instructions below in the Understanding and editing the “hosts” file contents part of this post.

6. Save your changes by selecting “Save” from the “File” menu or by simultaneously pressing the “CTRL” (Control) and “S” keys on your keyboard.

7. Close the Notepad text editor.

8. Clear your browser and DNS cache. We have provided a step-by-step-tutorial for the most popular browsers and operating systems at the end of this post.

You can access and edit the “hosts” file on macOS by following these steps:

1. Launch Terminal by opening a Finder window, selecting Applications from the sidebar, selecting Utilities, and double-clicking on Terminal.

2. Execute the following command in the Terminal window to open your “hosts” file with the GNU nano text editor:

sudo nano /etc/hosts

If you do not want to use the GNU nano text editor, you will need to update the command listed above to open the /etc/hosts file with your text editor of choice. In example, to open the “hosts” file with the Vim text editor, you need to execute this command:

sudo vim /etc/hosts

Note: You will be prompted to enter your Administrator password as editing the “hosts” file requires administrator privileges.

3. Adding new custom mappings to the “hosts” file is the same across all platforms. You can find detailed instructions below in the Understanding and editing the “hosts” file contents part of this post.

4. Save the changes you made to the “hosts” file. If you used the Nano text editor, you can save the changes by pressing the “Command” and “O” keys on your keyboard simultaneously.

5. Exit the text editor. To exit Nano press the “Command” and “X” keys simultaneously. If you did not save your changes, you will be prompted to save or discard them upon exiting Nano. You can save your changes by pressing the “Y” key on your keyboard or discard them by pressing the “N” key.

6. Clear your browser and DNS cache. We have provided a step-by-step-tutorial for the most popular browsers and operating systems at the end of this post.

To modify the “hosts” file on Linux, you should refer to the official documentation of the Linux distribution that you use. We will provide a detailed guide for Ubuntu (and most Ubuntu-derived distros); however, most of the steps should be applicable to most Linux distributions:

1. Open Terminal or a command line interface of your choice. You can open Terminal by using the default shortcut – simultaneously pressing the “CTRL” (Control), “Alt“, and “T” keys on your keyboard.

2. Next, you will need to open the “/etc/hosts” file on your computer with a text editor. To open the “/etc/hosts” file with the GNU nano text editor, you should execute the following command in Terminal:

sudo nano /etc/hosts

If you want to use the Vim text editor, execute this command:

sudo vim /etc/hosts

3. Adding new custom mappings to the “hosts” file is the same across all platforms. More information is available in the Understanding and editing the “hosts” file contents part of this post.

4. Save the file. If decided to use Nano, you can save your changes to the “hosts” file by pressing the “CTRL” (Control) and “O” keys on your keyboard simultaneously.

5. You should exit the text editor after the changes are saved. You can exit Nano by pressing the “CTRL” (Control) and “X” keys on your keyboard simultaneously. If you did not save your changes, you can choose to save or discard the most recent changes by pressing the “Y” or “N” keys on your keyboard respectively.

6. Clear your browser and DNS cache. We have provided a step-by-step-tutorial for the most popular browsers and operating systems at the end of this post.

You can open your “hosts” file quite easily on Windows 7 and Windows Vista:

1. Open the “Run” application by pressing the “Windows” and “R” keys on your keyboard.

2. Enter the following command in the “Run” application to open your “hosts” file with Notepad:

notepad %WinDir%\system32\drivers\etc\hosts

Note: You will need to grant Notepad administrator permissions by pressing the Continuebutton in the Windows needs your permission window that will appear.

3. Adding new custom mappings to the “hosts” file is the same across all platforms. You can find detailed instructions below in the Understanding and editing the “hosts” file contents part of this post.

4. Save your changes by selecting “Save” from the “File” menu or by simultaneously pressing the “CTRL” (Control) and “S” keys on your keyboard.

5. Close the Notepad text editor.

6. Clear your browser and DNS cache. We have provided a step-by-step-tutorial for the most popular browsers and operating systems at the end of this post.

Editing the hosts file on Windows XP, Windows NT, and Windows 2000 requires that you take the following actions:

1. Open the Windows Start Menu by clicking on the Windows Start icon on the left end of the Taskbar, or by pressing the “Windows” key on your keyboard.

2. Start the Notepad text editor from the “Accessories” menu under “All Programs“.

3. Open the “hosts” file in Notepad – click on “Open” from the “File” menu, enter

%WinDir%\System32\drivers\etc\hosts

in the “File name” field, and click on the “Open” button.

4. Adding new custom mappings to the “hosts” file is the same across all platforms. You can find detailed instructions below in the Understanding and editing the “hosts” file contents part of this post.

5. Save your changes by selecting “Save” from the “File” menu or by simultaneously pressing the “CTRL” and “S” keys on your keyboard.

6. Close the Notepad text editor.

7. Clear your browser and DNS cache. We have provided a step-by-step-tutorial for the most popular browsers and operating systems at the end of this post.

Understand and edit the “hosts” file contents

As we mentioned earlier, accessing the “hosts” file will depend on the operating system running on your computer; however, new custom mappings are added to the “hosts” file the same way across all operating systems. Generally, you have to enter an IP address and a hostname separated by an interval on a new line. So, if you want to see the website for domain1.com from the web server at 0.0.0.0 and the website for domain2.com from the web server at 255.255.255.255, you will need to add the following lines to your local “hosts” file:

0.0.0.0 domain1.com
255.255.255.255 domain2.com

Note: Of course, you will need to replace the example domain/s and IP address/es with your domain name and the IP address/es with the IP address of your hosting provider’s web server. We would recommend that you contact your hosting provider for the IP address of their web server as this information may not be easily accessible. With ICDSoft, the IP address of the web server is visible under “IP Addresses” from the “Information” section on the left side of the hosting Control Panel.

We added two custom mappings for hostnames domain1.com and domain2.com to our local hosts file; however, these mappings will not affect the hostnames with the WWW prefix (www.domain1.com and www.domain2.com). To resolve this, we can add two more lines to our hosts file, but there is an easier way – we can map the www and non-www hostnames to a single IP address by adding both of them after the IP address:

0.0.0.0 domain1.com www.domain1.com #mapping both domain1.com and www.domain1.com to 0.0.0.0

As you have probably seen in the example listed above, you can insert comments to your “hosts” file by adding the hashtag symbol (#) after a custom mapping or at the start of a new line:

# This is a comment
0.0.0.0 domain1.com             #This is a comment
255.255.255.255 domain2.com     #This is a comment

Clear your browser cache and cookies and purge your DNS cache

After you added the necessary custom mappings to your “hosts” file, you should clear your browsing cache and cookies and purge your DNS cache. This step is necessary as your browser and/or DNS cache may cause some website elements to load from the web server listed in the DNS and others from the web server specified in your “hosts” file.

Before we provide you with the steps to clear your browsing data, we should mention that this may log you out of websites, empty your online shopping carts, remove some of your address bar suggestions, etc.

You can access the window/menu that allows you to clear your browsing data on the most popular web browsers (Mozilla Firefox/Google Chrome/Apple Safari/Opera/Microsoft Edge) quite easily. All you need to do is simultaneously press the “CTRL” (Control), SHIFT“, and “DELETE” keys on your keyboard. If you are using macOS, you should press “CMD” (Command) instead of the “CTRL” (Control) key on your keyboard.

In the window/menu that appears, we would recommend that you choose to clear only the cache (cached data and files) and cookies (cookies and saved website data) and leave the other options unchecked.

It is worth mentioning that Google Chrome has its own DNS cache. To clear this cache, follow the steps listed below:

  • Enter the following URL in the address bar of Google Chrome:
    chrome://net-internals/#dns
  • Click on the “Clear host cache” button.
  • Go to “Sockets” from the navigation menu on the left.
  • Click on the “Flush socket pools” button.

The next and final step of the process is to flush the local DNS cache of your computer. Depending on your computer’s operating system, here is what you need to do:

1. Open the “Run” application by pressing the “Windows” and “R” keys on your keyboard.

2. Enter the following command in the “Run” application to the Windows Command Prompt:

cmd

3. Press the “ENTER” key on your keyboard to execute the command.

4. Enter the following command in Windows Command Prompt:

ipconfig /flushdns

5. Press the “ENTER” key on your keyboard to execute the command.

6. You should see the following success message:
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.

Note: If you receive an error/warning message that administrator privileges are required, start all over again, but in step 3 press simultaneously theCTRL” (Control), “SHIFT“, and “ENTERkeys on your keyboard instead of pressing only theENTERkey. This will open the Windows Command Prompt with administrator privileges.

1. Launch Terminal by opening a Finder window, selecting Applications from the sidebar, selecting Utilities, and double-clicking on Terminal.

2. Execute the following command in the Terminal window:

sudo killall -HUP mDNSResponder

Note: You will be prompted to enter your Administrator password as this command requires administrator privileges.

3. Close Terminal.

Clearing the DNS cache on all Linux distributions is more complicated as they use different DNS services. To add further complexity to this, you can also install an alternative DNS service of your choice, which will make the default solution ineffective. We will suggest that you refer to the official documentation of the Linux distribution or DNS service that you use.

You can clear the DNS cache on Ubuntu (a default installation) or the DNS cache of the most popular alternative DNS services for Linux by following the steps listed below:

1. Open Terminal or a command line interface of your choice. You can open Terminal by using the default shortcut – simultaneously pressing the “CTRL” (Control), “Alt“, and “T” keys on your keyboard.

2. Execute the following commands if you are running a default Ubuntu installation:
sudo /etc/init.d/dns-clean restart
sudo /etc/init.d/networking force-reload

To clear the DNS cache of dnsmasq, use this command:
sudo /etc/init.d/dnsmasq restart

If you are using the name service cache deamon (nscd), execute this command:
sudo /etc/init.d/nscd restart

Should BIND 9 (binddns) be your alternative DNS service of choice, run these commands in Terminal:
sudo /etc/init.d/named restart
sudo rndc restart
sudo rndc exec


This brings us to the end of this post. We covered everything you need to know about getting a website working from another location just for you. You learned how to find and use your “hosts” file, as well as clearing your browsers cache and sessions and your DNS cache.

As always, you can contact our friendly support team if you have any questions about the settings that you need to use in your “hosts” file.

If you learned something new, or if you liked this post, make sure to share it.