How to edit your hosts file

By Michael Argentini
Managing Partner, Technology and Design

Sometimes testing a development or staging web application requires the use of production domains. For example, you want to make sure your 301 redirects are working prior to launch.

Modifying your hosts file enables you to override the DNS for a domain on your computer. This is useful when you want to test your site prior to going live with SSL, verify that a development site works prior to DNS changes, and for other DNS-related reasons. Modifying your hosts file causes your local machine to look directly at the IP address you specify.

When modifying the hosts file, you add two entries: the IP address to which you want the domain to resolve, and the domain. Adding the following two lines, for example, you could point to your local machine:

After you add the domain information and save the file, your system begins resolving to the specified IP address. After testing is finished, you would remove any of these test entries.


Windows 10, Windows 8, Windows 7, and Windows Vista use User Account Control (UAC), so Notepad must be run as Administrator.

For Windows 8 and 10

  1. Press the Windows key.
  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
  5. Make the necessary changes to the file.
  6. Click File > Save to save the changes.

For Windows 7

  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.
  6. Click Open.
  7. Make the necessary changes to the file.
  8. Click File > Save to save your changes.


OS X 10.6 through 10.11, macOS 10.12, 10.13

  1. Open Applications > Utilities > Terminal.
  2. Open the hosts file by typing the following line in the terminal window:
    sudo nano /private/etc/hosts
  3. Type your domain user password when prompted.
  4. Edit the hosts file.

    The file contains some comments (lines starting with the # symbol), and some default host name mappings (for example, – local host). Add your new mappings after the default mappings.

  5. Save the hosts file by pressing Control+X and answering Y.
  6. Make your changes take effect by flushing the DNS cache with the following command:
    dscacheutil -flushcache
  7. The new mappings should now take effect.

Article last updated on 4/28/2018