How to Edit your Host File

A website is a series of code that resides on a server. 

DNS is used to point to that server.  In the case of migrations or backups, you may have the same site files on 2 different servers. DNS tells the internet which server to access. 

Maybe you need to work on the new site on the new server, but you don't want everyone else to access it yet. 

 

In that case, you can point your local DNS to access the new server when you visit a site. 

 

We can do this by editing our Hosts File.  

*Note- Make sure you right click and open the Host file as an admin user. 

*Note 2 - Clear your browsers cache after you change DNS so your computer will load the new site. How to Clear your Browsers Cache

The following instructions are advanced steps for different operating systems.

Windows

Windows users are able to edit their hosts file directly on their PC.

Windows 8

  1. Select the Start key and locate Notepad. (If you do not see it on your current Start page, type "Notepad" and press Enter).
  2. Right click on Notepad. You will see options appear on the bottom portion of the Start Page.
  3. Select Run as administrator.
  4. Browse to C:\Windows\System32\Drivers\etc and open the hosts file.
  5. Make the needed changes, as shown above, and close Notepad. 

    You will add a line similar to what is below. Replace the IP with the IP from your Welcome Email, and the domain.com and www.domain.com with your domain.

    123.45.67.89 domain.com www.domain.com


  6. Save when prompted.

Windows 7 or Vista

  1. Browse to Start > All Programs > Accessories.
  2. Right-click Notepad, and select Run as administrator.
  3. Click Continue on the UAC prompt.
  4. Click File > Open.
  5. Browse to C:\Windows\System32\Drivers\etc.
  6. Change the file filter drop-down box from Text Documents (*.txt) to All Files (*.*).
  7. Select hosts, and click Open.
  8. Make the needed changes, as shown above, and close Notepad.

    You will add a line similar to what is below. Replace the IP with the IP from your Welcome Email, and the domain.com and www.domain.com with your domain.

    123.45.67.89 domain.com www.domain.com
  9. Save when prompted.

 


Mac OS X

Follow the instructions below to edit your hosts file if you are running Mac OS X.

  1. Open the Terminal application. Start by typing Terminal on the Spotlight or by going to Applications > Utilities > Terminal.
  2. Open the hosts file by typing in the Terminal that you have just opened:

    sudo nano /private/etc/hosts

    Note: Some versions of Mac OS X will lock permissions on the hosts file (the file is marked as immutable). In the event this happens, use the following command instead: sudo chflags nouchg /private/etc/host
  3. Type your user password when prompted.
  4. The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 localhost). Simply append your new mappings underneath the default ones. You can navigate the file using the arrow keys.

    123.45.67.89 domain.com www.domain.com

    Replace "123.45.67.89" with the server IP that HostGator provided you in your cPanel. Replace domain.com with your actual domain name. Additional domains, subdomains or addon domains (such as www.domain.com) can be added at the end of the line, separated by spaces.
  5. When done editing the hosts file, press Control-o to save the file.
  6. Press Enter on the filename prompt, and Control-x to exit the editor.
  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Clear Cache

How do I clear my web browser's cache, cookies, and history?   Notes: In most computer-based...

Email Migration

We are only able to migrate emails from other cPanel hosts. Using a 3rd party email system like...

Powered by WHMCompleteSolution