Your computer’s “host” file and you.

Your computer’s “host” file is used to map a hostname to an IP address in a local area network (LAN) and/or wide area network (WAN).

Great, so what does that mean? Well say you a created a web server on a Virtual Machine (VM) for testing and you wanted to access the machine by the domain name you assigned it. You could add or update a Domain Name Server (DNS) and point the domain to a public IP address. But, if the web server is in a LAN it may not be accessible and it might take a few hours for you Internet Service Provider’s (ISP) to populate your DNS update.

To save time you could update your computers host file. This plain text file is on Linux and Windows machines that is used first when making calls to domain names. All you need is the IP address of the server and the domain name.

Editing the host File.

For this example we will be using Windows 7. But, most operating systems (OS) use the same general process.

  • Click the Windows Start button.
  • Click the All Programs menu option.
  • Click to open the Accessories menu folder.
  • Right-mouse-click on the Notepad menu option.
  • In the Notepad program window left-click the File
    menu option on the main menu bar.
  • Next click the sub-menu option Open.
  • In the Open dialog box navigate to the folder C:\Windows\System32\drivers\etc\. Initially the folder will appear empty.
  • In the bottom right of the dialog change the select box field from Text Documents (*.txt) to All Files (*.*). This will show you 4 to 5 files.
  • Click and highlight the file hosts
  • In the bottom right of the dialog press Open
  • The contents of an the file start like this:
    # Copyright (c) 1993-2009 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    #      102.54.94.97     rhino.acme.com          # source server
    #       38.25.63.10     x.acme.com              # x client host
    		
  • Scroll to the bottom of the document.
  • Type in the IP address, press the Tab key on your keyboard, and type the domain name.
  • Save the file change by pressing Ctrl-S on your keyboard.
  • Here I added a record to point to a WordPress test site that I added to my LAN.
    # Copyright (c) 1993-2009 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    #      102.54.94.97     rhino.acme.com          # source server
    #       38.25.63.10     x.acme.com              # x client host
    
    10.10.10.201	test.lighthouseknowledgedotcom.wordpress.com
    		

It should be noted that most browsers will automatically pickup on the changes to the host file. But, some browsers will need to be restarted to affect the changes.