How to change your Hosts File

The hosts file allows you to set IP addresses for a domain on your local computer. Changing your hosts file is a temporary measure to preview your site as it will load from your Create server. It lets you make changes on a server other than the one loaded by your domain when visitors access your page.

 

Hosts File is handy for development purposes, as you can work on your site on an alternate server using a hosts file while visitors may still visit and use your existing site.

 

How to Edit Hosts File

To change the host your domain loads from, you need to know your server's correct IP. Create servers will require you to use the IP address displayed in your cPanel under general information.

Screen_Shot_2021-06-01_at_3.46.39_PM.png

 

All operating systems will have a hosts file like the example example below:

127.0.0.1 localhost
123.45.67.89 www.example.com
#98.76.54.32 www.another-example.com

Add the second line in this example to your hosts file, with the following edits:

  1. Replace 123.45.67.89 with the IP address from your cPanel.
  2. Replace www.example.com with your actual domain name.

 

 

 

Editing Hosts File in Windows 8 and Windows 10

  1. To find the Windows hosts file location: Select the Start key and locate Notepad. (If you do not see it on your current Start page, begin typing Notepad, and a search box will appear on the right side of the screen with a list of programs under it. Notepad should be at the top of this list.
  2. Right-click on Notepad. You will see options appear on the bottom portion of the Start Page.
  3. Select Run as administrator.
    Note: Performing this action may cause Windows User Account Control to prompt you with a warning, or if you are logged in as another user, a request for the Administrator password. This step is necessary to modify system files such as the hosts file.
  4. Click File in the menu bar at the top of Notepad and select Open.
  5. Click the drop-down box in the lower right-hand corner that is set to Text Documents (*.txt) and select All Files (*.*)
  6. Browse the Windows Hosts File location:  C:\Windows\System32\Drivers\etc and open the hosts file.
  7. Make the needed changes, as shown above, and close Notepad.
  8. Save when prompted.

 

Editing Hosts File in Windows 7 or Vista

  1. To find the Windows hosts file location: 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.
  9. Save when prompted.

 

Editing Hosts File in Mac 

  1. To locate Mac hosts files location: Navigate to 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  
  3. Type your user password when prompted.
  4. The hosts file contains some comments (lines starting with the # symbol) and some default hostname mappings (e.g., 127.0.0.1 localhost). 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.

 

Editing Hosts File in Unix

  1. Go to Menu.
  2. Select Applications.
  3. Choose Accessories.
  4. Select Terminal.
  5. Open the hosts file by typing in the Terminal that you have just opened:
    sudo nano /etc/hosts
  6. Type your user password when prompted.
  7. The hosts file contains some comments (lines starting with the # symbol) and some default hostname mappings (e.g., 127.0.0.1 localhost). 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.
  8. When done editing the hosts file, press Control-o to save the file.
  9. Press Enter on the filename prompt and Control-x to exit the editor.
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.