Learn Using Hosts File to Test Websites

January 26, 2019

Table of Contents

The hosts file is a special file on your workstation computer that will store IP and name information. This file is checked before DNS, so if you place an entry in this file it will supersede anything set in DNS. This feature is very useful in testing websites as it will allow you to control which IP your local computer will visit regardless of what is set in DNS.

Hosts file syntax

The format of the hosts file is very simple. Each line has an IP address and a hostname separated by one or more spaces. By default, hosts files typically contain entries for “localhost” as well as some comment text describing the file and its use. It is best to not change any of these lines.

Example: example.com www.example.com

Editing your hosts file

  1. From the Start Menu, search for “Notepad” (Win 8, 10) or navigate to: “All Programs -> Accessories -> Notepad” (Win XP, Vista, 7).
  2. Right click on Notepad and select “Run As Administrator”.
  3. In Notepad, click “Open” and select the file C:WindowsSystem32Driversetchosts.
  4. Edit file and save.
  1. Open a terminal window.
  2. Edit the file /etc/hosts as root with a text editor. Example: sudo nano /etc/hosts

Testing your settings

  1. Open a command prompt.
  2. Use the command: ping -c2 example.com
  3. The ping results will show the IP address and confirm that it is responding.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!