How to Temporarily Point a Website to a Different IP Address Using the Windows Hosts File Print

  • change website IP, Windows hosts file, point domain to new server, flush DNS, temporary DNS change, test website before DNS, hosts file, preview website, edit hosts file, website migration, DNS testing
  • 0

The Windows hosts file allows you to temporarily tell your computer to load a website from a specific IP address, without changing the website’s public DNS records.

This is useful when testing a website on a new server before updating DNS, checking a migration, or previewing a site before it goes live.


What does the hosts file do?

Normally, when you visit a website such as example.com, your computer checks DNS to find the server IP address for that domain.

The hosts file lets you override this lookup on your own computer only. This means:

  • The change only affects your computer.
  • It does not change public DNS.
  • Other visitors will still see the normal live website.
  • You can safely remove the entry when testing is complete.

Important before you begin

You will need:

  • The domain name you want to test.
  • The IP address of the server you want the domain to load from.
  • Administrator access on your Windows computer.

Example:

192.0.2.123 example.com
192.0.2.123 www.example.com

Replace 192.0.2.123 with the server IP address you have been provided.


Step 1: Open Notepad as Administrator

  1. Click the Windows Start button.
  2. Type Notepad.
  3. Right-click Notepad.
  4. Select Run as administrator.
  5. If Windows asks for permission, click Yes.

Opening Notepad as administrator is important. If you do not do this, Windows may not allow you to save the hosts file.


Step 2: Open the hosts file

In Notepad, click:

File > Open

Then browse to:

C:\Windows\System32\drivers\etc

By default, Notepad may only show text files. In the bottom-right corner of the Open window, change:

Text Documents (*.txt)

to:

All Files (*.*)

You should now see a file named:

hosts

Select the hosts file and click Open.


Step 3: Add your temporary IP entry

At the bottom of the hosts file, add the IP address followed by the domain name.

For example:

192.0.2.123 example.com
192.0.2.123 www.example.com

Make sure there is at least one space between the IP address and the domain name.

If you want both the non-www and www versions of the website to load from the new IP address, add both entries.


Step 4: Save the hosts file

Click:

File > Save

If Windows asks for confirmation, allow the file to be saved.

If you receive a permission error, close Notepad and repeat the steps above, making sure you open Notepad using Run as administrator.


Step 5: Clear your DNS cache

After saving the hosts file, you may need to clear your local DNS cache.

  1. Click the Windows Start button.
  2. Type Command Prompt.
  3. Right-click Command Prompt.
  4. Select Run as administrator.
  5. Run the following command:
ipconfig /flushdns

You should see a message confirming that the DNS Resolver Cache has been flushed.


Step 6: Test the website

Open your web browser and visit the domain name.

If the hosts file entry is working, your computer should now load the website from the IP address you entered.

If the website still shows the old version, try:

  • Closing and reopening your browser.
  • Clearing your browser cache.
  • Using a private/incognito browser window.
  • Checking that the IP address and domain name were entered correctly.

How to remove the temporary hosts file change

Once testing is complete, you should remove the temporary hosts file entry.

  1. Open Notepad as administrator again.
  2. Open the hosts file from:
C:\Windows\System32\drivers\etc\hosts
  1. Delete the lines you added.
  2. Save the file.
  3. Flush DNS again using:
ipconfig /flushdns

Your computer will then go back to using normal public DNS for the domain.


Example hosts file entry

If your new server IP address is 203.0.113.50 and your domain is yourdomain.com.au, you would add:

203.0.113.50 yourdomain.com.au
203.0.113.50 www.yourdomain.com.au

Troubleshooting

The file will not save

Make sure you opened Notepad using Run as administrator.

The website still loads from the old server

Flush your DNS cache, restart your browser, and check that the hosts file entry is correct.

The website shows a security or SSL warning

This can happen if the website’s SSL certificate is not installed on the server you are testing, or if the server is not configured for that domain yet.

The website does not load at all

Check that the IP address is correct and that the hosting server has been configured to accept traffic for the domain.


Need help?

If you are unsure what IP address to use, or the website does not load correctly after updating your hosts file, please contact our support team and we can assist.


Was this answer helpful?

« Back