Skip to main content

How to Test a Website by Editing the Local Hosts File

You can test a website's functionality on your local computer before updating public DNS records by mapping a domain name to a specific IP address in your local hosts file. This allows you to verify that a website loads correctly on a new server while...

You can test a website's functionality on your local computer before updating public DNS records by mapping a domain name to a specific IP address in your local hosts file. This allows you to verify that a website loads correctly on a new server while the rest of the internet still sees the old version.

Before you begin

You will need:

  • A computer with administrative or administrator privileges.

  • The IP address of the server where the website is currently hosted or being moved to.

  • The domain name (e.g., example.com) you wish to test.

How to test a website locally

The process for editing the hosts file depends on your computer's operating system.

Windows

  1. Click the Start menu and type Notepad.

  2. Right-click Notepad and select Run as administrator.

  3. In Notepad, go to File > Open.

  4. Navigate to the following path: C:\Windows\System32\drivers\etc

  5. In the "Files" dropdown menu (next to the address bar), change the selection from Text Documents (*.txt) to All Files (.).

  6. Select the file named hosts and click Open.

  7. Scroll to the bottom of the file and add a new line with the IP address, a space, and the domain name. Example: 192.0.2.10 example.com

  8. Save the file and close Notepad.

macOS

  1. Open Terminal (found in Applications > Utilities).

  2. Type the following command and press Enter: sudo nano /etc/hosts

  3. Enter your system administrator password when prompted (characters will not appear as you type).

  4. Use the arrow keys to move to the bottom of the file.

  5. Add a new line with the IP address, a space, and the domain name. Example: 192.0.2.10 example.com

  6. Press Control+O to save the changes, then press Enter to confirm the filename.

  7. Press Control+X to exit the editor.

Confirm the result

  1. Open a web browser.

  2. Clear your browser cache or open a private/incognito window.

  3. Type the domain name (e.g., example.com) into the address bar.

  4. The browser should load the website from the IP address specified in your hosts file.

If the website still shows the old version

If the site does not update after you have edited the hosts file, your computer may be using a cached DNS result.

  1. Clear your local DNS cache.

    • Windows: Open Command Prompt and type ipconfig /flushdns.

    • macOS: Open Terminal and type sudo dscache_ -flushdns.

  2. Restart your browser.

  3. Check for a Proxy or VPN. If you are using a VPN or a proxy service, it may bypass your local hosts file settings. Disable these services to test the local connection.

Limitations

  • Local Scope: This change only affects the computer you performed the edit on. Other devices and users will still see the original site until the public DNS records are updated.

  • Browser Caching: Browsers often cache DNS and site data. If you see the old site, try an Incognito window to bypass the cache.

  • Reversion: To return to normal browsing, you must delete the line you added to the hosts file or restart your computer.

Did this answer your question?