Pointing localhost File to Preview Site

The hosts file on your computer allows you to override DNS and manually map hostnames (domains) to IP addresses. This can come in handy during migrations as you might want to see how the website looks on a different server, but perhaps DNS hasn’t been pointed to the new server or propagated yet. Modifying your hosts file causes your local machine to look directly at the Internet Protocol (IP) address that you specify. This involves adding two entries to it. Each entry contains the IP address to which you want the site to resolve and a version of the Internet address.

165.227.218.225 domain.com
165.227.218.225 www.domain.com

Now let’s look at accessing the hosts files in the different operating systems…

Windows 10

Step 1: Open Notepad as an Administrator

You’ll need administrator privileges for this operation.

  1. Click the Windows button and type “notepad” Let the search feature find the Notepad application.
  2. Right-click the Notepad app, then click Run as administrator
  3. Windows User Account Control should pop up asking, “Do you want to allow this app to make changes to your device?” Click Yes

Step 2: Open the Windows Hosts File

  1. In Notepad, click File > Open
  2. Navigate to c:\windows\system32\drivers\etc
  3. In the lower-right corner, just above the Open button, click the drop-down menu to change the file type to All Files
  4. Select “hosts” and click Open

 

 

Step 3: Edit the File

Add the IP address and host name in the following format where 0.0.0.0 is the IP of the server where the website is hosted…

0.0.0.0 domain.com
0.0.0.0 www.domain.com

 

 

Once you’re finished making your changes, save the file ( File > Save ) and exit.

If you make an edit to the hosts file and something stops working, you can tell Windows to ignore any line by putting a # sign at the beginning of that line.

Windows 7

To access the hosts file in Windows 7 you can use the following command in the Run Line to open notepad and the file.

notepad c:\windows\system32\drivers\etc\hosts

Windows 7 Run

Once Notepad is open you can edit the file per the above instructions.

Mac OS

Step 1: Open the Mac Terminal

Open the Finder , and go to Applications > Utilities > Terminal

Type the following in the terminal window…

sudo nano /etc/hosts

The system will prompt you to enter your password – this is the same password you use to log in to the system. Type it in, and hit Enter .

Step 2: Edit Mac Hosts File

The IP address is first, and the server name comes second. Comments are indicated with a ‘#’ sign.

0.0.0.0 domain.com
0.0.0.0 www.domain.com

Enter the IP address you want to refer to first, hit tab, and then the server name (or domain name) that you want to associate with it.

Mac Hosts File

Save your changes by pressing Control + O , then exit by pressing Control + X .

Was this article helpful?
0 out of 0 found this helpful

Articles in this section

See more
Reclaim Hosting Support Hours
8:00 am - 5:00 pm ET, Monday through Friday
Submit a Ticket
Get a quick and helpful response from the pros.
Need Extra Support?
No problem, we're here to help! Talk to us about Professional Services or custom Service Level Agreements.