Modifying your HOSTS file to Preview Site

There are times you will need to check a site before switching the DNS to launch it, like when moving a website to a new webserver. A good way to do this before updating your DNS is to modify your local Hosts file. This tells your computer to use an overriding IP address for your site instead of where the domain's DNS servers say it is.

Note: you should change it back or remove any settings you make to your Hosts file once the domain's DNS has been updated and the new site is live.

The Easy Way: Edit with an Application

The easiest way to edit your Hosts file on your computer is to use an application rather than edit it manually. The following open-source (free) apps should enable you to change your Hosts file without getting too nerdy: 

Manually Editing a Hosts File

An example Hosts entry would look like the following:

123.45.67.89 example.com www.example.com preview.example.com

This would tell your local computer to use that IP for those sites, instead of what their DNS record says.

Windows

For current Windows versions, the easiest way to edit your Hosts file is to use the open-source HostsFileEditor. If you wish to do it manually, you can follow the instructions below for your version of Windows. 

Windows 11, 10 and 8

  1. Press the Windows key on your keyboard.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
    you will need to change the file type filter to All files (*.*) to see it in the open file dialogue.
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.

For Windows 7 and Vista

  1. Click Start > All Programs > Accessories.
  2. Right-click Notepad and select Run as administrator.
  3. Click Continue on the Windows needs your permission UAC window.
  4. When Notepad opens, click File > Open.
  5. In the File name field, type C:\Windows\System32\Drivers\etc\hosts
    you will need to change the file type filter to All files (*.*) to see it in the open file dialogue.
  6. Click Open.
  7. Make the necessary changes to the file.
  8. Click File > Save to save your changes.

For macOS, OS X 10.7 (Lion) through macOS 12.1 (Monterey)

The simplest option is to use Hosts.prefpane but if you prefer the hands on approach, here's the details

  1. Open Terminal.app. The easiest way to do this is to type cmd+space and search for it with Spotlight.
  2. Type the following to modify your Hosts file:
    sudo nano /private/etc/hosts
  3. Type your admin password at the prompt.
  4. Make the necessary changes to the Hosts file.
    The file contains some comments (lines starting with the # symbol), and some default hostname mappings (for example, 127.0.0.1 – localhost). Add your new mappings after the default mappings.
  5. Save the hosts file by pressing control+x and answering y.
  6. In all versions of OSX/macOS except Yosemite (10.10) flush your local DNS cache as follows to make the change take effect:
    sudo killall -HUP mDNSResponder
    In OSX Yosemite (10.10) you can use the following: 
    sudo discoveryutil udnsflushcaches

 

  • 0 Users Found This Useful
Was this answer helpful?