How To: Modify Your Hosts File

Sometimes, when in the process of working on a site with us, we’ll ask you to evaluate a development copy of your site. These are potentially hosted on servers that have a different IP address than your “live” site. When this happens, the simplest way to view the site is to override the DNS entries using a hosts file.

Modifying your hosts file causes your local machine to route requests for a particular domain, such as example.com to a particular IP address. The hosts file looks like a collection of records that map domains to IP addresses, for example:

70.60.131.251 example.bcsengineering.com

In this article, we provide instructions for modifying your hosts file for the following operating sytems:

  • Windows 10, Windows 8, Windows 7, and Windows Vista
  • Linux
  • Mac OS X 10.6 through 10.12

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


Windows

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

Instructions:

  1. 1. Press the Windows key.
  2. 2. Type “notepad” in the search field.
  3. 3. In the search results, right-click the Notepad icon and select Run as administrator.
  4. 4. Click Continue on the window that opens requesting permission to run as an administrator.
  5. 5. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  6. 6. Make any changes that you’d like to make. Entries should include both an IP address and a domain name or collection of domain names.7. Click File > Save to save your changes.

Linux

Much like Windows, most Linux operating systems will require administrative privileges in order to edit the hosts file. This is achieved from the terminal by escalating your user’s privileges using sudo. If you do not have sudo access for your computer, contact your local administrator.

Instructions:

  1. 1. Open a terminal window.
  2. 2. Open the hosts file in a text editor (you can use any text editor) by typing the following line:
    sudo vim /etc/hosts
    
  3. 3. Enter your password.
  4. 4. Press i to enter “insert mode”, and navigate using the arrow keys to the location in the file where you want to make changes.
  5. 5. Make any changes that you’d like to make. Entries should include both an IP address and a domain name or collection of domain names.
  6. 6. Press ESC, then wq. This exits “insert mode”, writes the file, and quits.

Mac OS X

Much like Windows and Linux, Mac systems will require administrative privileges in order to edit the hosts file. This is achieved from the terminal by escalating your user’s privileges using sudo. If you do not have sudo access for your computer, contact your local administrator.

Instructions:

The following instructions are valid for Mac OS X 10.4 through 10.12:

  1. 1. Open Applications > Utilities > Terminal.
  2. 2. Open the hosts file by typing the following line in the terminal window:
    sudo vim /etc/hosts
    
  3. 3. Enter your password.
  4. 4. Press i to enter “insert mode”, and navigate using the arrow keys to the location in the file where you want to make changes.
  5. 5. Make any changes that you’d like to make. Entries should include both an IP address and a domain name or collection of domain names.
  6. 6. Press ESC, then wq. This exits “insert mode”, writes the file, and quits.
  7. 7. Make your changes take effect by flushing the DNS cache with the following command:
    dscacheutil -flushcache

The new mappings should now take effect.


If you are a BCSE customer in need of help adjusting your hosts file, please open a ticket with us at support.bcsengineering.com