Skip to end of metadata
Go to start of metadata

Sometimes you may find you need to access a domain which you have not yet configured public DNS for.  Did you know you can use your computer’s Hosts file to direct it to the correct IP address of the domain you are working on and preview the domain before you update your public DNS? This is a great way to preview a website that's in the process of being built or modified to make sure things work before you update your public DNS.

Modifying Your Hosts File in Windows

The Hosts file in Windows is conveniently located in C:\Windows\System32\drivers\etc\hosts.

You can open this file in Notepad or a text editor of your choice.  You will need to be running Notepad as an Administrator in order to edit the file.

Right Click the Notepad icon in your Start Menu or Desktop.  Click Run as administrator.

If prompted, click Yes to allow the program Administrative access.

Once in Notepad, click File → Open.

Navigate to C:\Windows\System32\drivers\etc\. You may need to select All Files in the dropdown next to the filename in order for the files to show.  Select hosts and click Open.

You should now see a file that looks like this:

Add in the IP address of your server and the domain you would like to access.  Add both the www and non-www versions for greater flexibility.

Click File → Save to save your changes.  You should now be able to access your domain at the IP address you assigned.

Modifying Your Hosts File in MacOS / Linux

Both Linux and MacOS locate the hosts file in /etc/hosts.  MacOS in particular keeps this location hidden in the graphical interface, so you will need to edit the file from a command line.  Assuming Linux users know how to access their terminal, this tutorial will be written with the MacOS interface in mind.

Click the spyglass icon in the upper right corner to open Finder.  Type Terminal in the search box and press Return to open it.

Once open you will see a command line.  Type sudo nano /etc/hosts and enter your administrative password if prompted to open the file.

Use the arrow keys to navigate and insert text.  The “^” in the commands at the bottom corresponds to the Ctrl key on the keyboard. Add in the IP address of your server and the domain you would like to access.  Add both the www and non-www versions for greater flexibility. Press Ctrl+O to write the file. Press Ctrl+X to exit.

You should now be able to access your domain at the IP address you assigned.