How to Edit Hosts File

July 20, 2017 / How-to Guide

Hosts file is basically simple plain-text file which contains a list of host names and their corresponding IP addresses.

Editing your hosts file overrides the DNS entries for any domain by resolving that domain to the IP address of your choice, this change only affects the computer you are making the change on which makes it very useful for testing websites, for example when performing a migration.

Where is hosts file ?

c:\Windows\System32\Drivers\etc\hosts

How to Edit hosts file ?

Here are the steps to Editing your hosts file on Window 8, 8.1 and 10

  1. From your start menu locate notepad, right click and select Run as administrator (You may be asked to enter your administrator password at this point)
    run_notepad
  2. Navigate to C:\Windows\System32\drivers\etc (this assumes Windows has been installed to the default directory)
  3. To the right of Filename select All Files (*.*)
  4. Open the file named hosts
    how to edit hosts file
  5. Create a new line at the bottom and enter the IP address of you new website followed by the domain name, for example:
    192.168.0.10 mywebsite.co.uk www.mywebsite.co.uk
    edit hosts file

Note: Wildcard entries are not supported within the hosts file, in the example above we have included both the non-www and www version of the domain.

  • Select File > save
  • The change is immediate, now when you enter your domain into your browser it will resolve to your new website allowing you to test your site before going live.

How to disable your hosts file entries ?

If you need to revert back so your domain points at the original IP you can either delete the line you entered and save or you can comment it out by prefixing the line with # which allows you to easily switch between your old and new sites for testing.

hosts_file_comment
This entry has been disabled by adding a #

As soon as you save the change will take affect.

Using Linux or macOS?

The hosts file and syntax used is standard across almost all operating systems, on Linux or macOS you can find the hosts file here: /etc/hosts

Dominos Search