How do I modify the Hosts file on my PC?

How to modify your computer’s Hosts file.

Much like DNS, your computer’s Hosts file associates IP addresses to host names. You may not always have control over DNS, but you can always have control over your Hosts file. The Hosts file can be used to resolve domain names without the use of DNS.

Why you would want to make changes to the Hosts file:

  • to preview websites in development
  • to do network testing
  • to increase browsing speeds (by bypassing the DNS query process)

Most hosting platforms don’t offer a “site preview” tool for website development. So, for further explanation of the Hosts file, I’m going to use the development scenario as an example of how to use it.

For example, you have your website loaded on a development server, but want a way to preview the site to ensure all the changes are working properly before changing the DNS and taking the site live.

You would first open your hosts file to point the domain name to the development server’s IP address.

This is how it’s done on a Windows 7 operating system:

  • Open the Start menu, go to Accessories, then find the program Notepad.
  • Once you’ve located Notepad, right-click on the icon and choose ‘Run As Administrator’
  • You will likely get the following message, you will want to select ‘Yes’

123

  • From inside the Notepad program you will go to My Computer, then Local Disk ( C: ) Then Windows, Then System32, Then Drivers and finally the folder etc.

123hosts

  • You will notice it says ‘no items match your search.’ At the bottom of the screen type “Hosts” where it says File Name: and this will allow the file to open in notepad.

123hosts2

  • Your screen should show the following information:

# Copyright (c) 1993-1999 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

  • You will then add the IP address of the development server to the bottom of the Hosts file, hit “Tab” on the keyboard, and then add the host name(s). This is what the final Hosts file would look like for this scenario:

# Copyright (c) 1993-1999 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
64.56.96.23         donet.com
64.56.96.23         www.donet.com

  • Now, just save the Hosts file and browse to the site. Your system will bypass DNS for that domain name and only pull content from the server you specify, basically showing you how that site would behave if the DNS records were pointing to it.

I should note that if you try this exact example, you will not see a difference in the Donet website as this is the current location of the site hosting.

If you have any questions please, contact DataYard Support.

Recommended Posts