Web Hosting
David Addison
by David Addison
share this
?fl
« Back to the Blog

Modifying Your Host File

02/27/2013
Modifying Your Host File

Setting Up a Local Domain Using the Host File

The hosts file is used by the operating system to map hostnames to IP addresses.  Most operating systems have a method of controlling the Domain Name System (DNS) for the local computer. For more on DNS, go to http://en.wikipedia.org/wiki/Domain_Name_System . The following steps will help you set up your localhost DNS for viewing websites on your local computer.

At Dirigo we often deploy test servers on live production IP addresses.  We tend to use the .test extension (e.g. http://www.newsite.test). The .test top level domain (TLD) extension does not even exist.  Since we don't setup public DNS for our test domains, the only way to map the DNS is on a loacl system.

Windows Windows 7 - Windows 10

The hosts file is located in the %SystemRoot%\system32\drivers\etc\ directory.  Open Notepad as administrator and browse to that location.  To open Notepad as an administrator, right click instead of clicking the Notepad icon.  Then open as administrator. You may need to select "All Files (*.*)" from the file type drop down menu.  Open hosts.  This is where you map an IP address to a domain name. 

  1. Type an IP address on the left side of the document, i.e. 127.0.0.1 for home. 
  2. Hit the 'tab' key (you must separate the IP and Domain name with a tab)
  3. Type in the domain name you wish to direct to the IP address. 

example:

127.0.0.1    <tab>     www.myWebSite.local

Be sure to not save the file as a .txt file.  The best way to save is <cntl> + the S key. Once saved open your browser and test the domain name.  You're done.  Close Notepad and go about your business.

Mac OS X

Hosts file is located in the /etc/ directory (or /private/etc/ for Leopard and earlier versions).  You will need to open the terminal (Unix) in order to edit your host file.  The terminal can be located under Applications -> Utilities -> Terminal.  This will be slightly easier if you are familiar with the terminal.

Enter the following command to open the local host file. You will need to open this file as root because the sudo command requires an admin password.

$ sudo vi /etc/hosts

You can now edit the host file. To add a new host entry, on it’s own line enter it in the format:

IP Address Host
127.0.0.1 www.myWebSite.local
Save the changes to your host file by pressing SHIFT + Z two times in vi.

As soon as you save the host file the changes you made will take effect. To check the changes, you can ping the host you entered to see if it returns the correct address or just browse to the host in Safari or Firefox.

Thanks!

Thank you for contacting us!

We'll be in touch!

Back Home ×