How to change your local machines host file to preview your site Print

  • 31

When you are migrating your website to Host Media, or making changes that involve DNS updates, your site will not be visible at your domain until DNS has propagated. Editing your computer's hosts file lets you bypass DNS entirely and view your site on the new server immediately, using your real domain name.

This is useful for testing your site looks and works correctly before pointing your domain, without affecting what anyone else sees.

Prefer a quicker option? If you just want a fast visual check without editing any files, you can use SkipDNS to preview your site via the browser with no setup needed.

Step 1: Find your server's IP address

You will need the IP address of your Host Media server before editing the hosts file. You can find this in two places:

  • Your welcome email: the IP address is listed in the hosting account details we sent when your account was set up
  • cPanel: log in to cPanel and look in the top-right area of the main dashboard. Your shared IP address is displayed there, or under General Information on the left sidebar

Make a note of the IP before continuing, you will need it in the next step.

Step 2: Edit your hosts file

Windows

  1. Open the Start menu and search for Notepad.
  2. Right-click on Notepad and select Run as administrator. This is required, without administrator rights you will not be able to save changes.
  3. In Notepad, go to File → Open and navigate to:
    C:\Windows\System32\drivers\etc\hosts
    Make sure the file type dropdown is set to All Files, otherwise the hosts file will not appear.
  4. Add the following lines at the bottom of the file, replacing 208.0.0.0 with your actual server IP and the domain names with your own:
208.0.0.0 yourdomain.com
208.0.0.0 www.yourdomain.com
  1. Save the file (File → Save).
  2. Open Command Prompt and run the following to flush your DNS cache so the change takes effect immediately:
    ipconfig /flushdns

macOS

The easiest method on Mac is to use Terminal:

  1. Open Terminal (find it in Applications → Utilities, or search with Spotlight).
  2. Run the following command to open the hosts file in the nano text editor:
    sudo nano /etc/hosts
    You will be prompted for your Mac login password.
  3. Use the arrow keys to move to the bottom of the file and add:
    208.0.0.0 yourdomain.com
    208.0.0.0 www.yourdomain.com
    replacing the IP and domain with your own.
  4. Press Ctrl+O to save, then Enter to confirm the filename, then Ctrl+X to exit nano.
  5. Flush your DNS cache by running:
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Linux

  1. Open a terminal and run:
    sudo nano /etc/hosts
  2. Add your entries at the bottom of the file:
    208.0.0.0 yourdomain.com
    208.0.0.0 www.yourdomain.com
  3. Save with Ctrl+O, then exit with Ctrl+X.
  4. Flush your DNS cache. The command varies by distribution:
    Ubuntu/Debian: sudo systemctl restart systemd-resolved
    Older systems: sudo /etc/init.d/nscd restart

Example hosts file entry

##
# Host Database
##
127.0.0.1       localhost

# Host Media preview — remove when DNS has propagated
208.0.0.0       yourdomain.com
208.0.0.0       www.yourdomain.com

We recommend adding a comment above your entries (lines starting with #) so you remember why they are there and can remove them easily later.

Step 3: Verify it is working

Open your browser and navigate to your domain. If the hosts file is working correctly, you will see the site as it exists on the Host Media server, regardless of where your DNS currently points.

To double-check which IP your domain is currently resolving to from your machine, open a command prompt or terminal and run:

ping yourdomain.com

The IP shown in the ping response should match the one you entered in your hosts file.

Step 4: Remove the entry when you are done

Once your DNS has fully propagated and your site is live, remove or comment out the hosts file entries you added. If you leave them in place, your computer will continue bypassing DNS and always load the site from the Host Media server IP, which can cause problems if the IP ever changes.

To comment out an entry, add a # at the start of the line:

# 208.0.0.0 yourdomain.com
# 208.0.0.0 www.yourdomain.com

Was this answer helpful?

« Back