Beginner’s Guide: How Do I Change My Hosts File?

0
29
Beginner's Guide: How Do I Change My Hosts File?

How Do I Change My Hosts File?

What Is a Hosts File?

The hosts file allows you to set IP addresses for a domain on your local computer that may override the authoritative DNS. This will allow you to see what a domain will display if it is pointed to a different server. This article covers the following topics:

  • How to Recognize a Hosts File?
  • Why Change the Hosts File?
  • Editing Your Hosts File
    • Browser Plugin
    • Editing System Files
  • DNS Flush

How to Recognize a Hosts File?

The hosts file is a plain text file, and is usually named hosts. A typical hosts file will have one or more lines referencing your local computer (as ‘localhost’) and will resemble this:

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

A hosts file can be edited to override your network settings and thus allow your local machine to view a website prior to the DNS changes propagating.

Why Change the Hosts File?

Changing your hosts file is a temporary measure to preview your site as it will load from your Itsmydomain server. This lets you make changes on a server other than the one loaded by your domain when visitors access your page.

This is very useful 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.
Itsmydomain recommends changing your hosts file for development. It provides the most stable development environment. Other methods can cause configuration issues after development is complete.

Editing Your Hosts File

To change the host your domain loads from, you will need to know the correct IP for your server. Itsmydomain servers will require you to use the IP address displayed in your cPanel.

You can view your IP by accessing your cPanel

Once you know your server IP address, there are 2 ways that you can change the host your domain loads from. This article will cover each of them:

  • Browser Plugin
  • Editing System Files

Note: Remember to undo and changes you make after you’re done viewing your site, as any of these changes will prevent your domain from loading the correct DNS.

Browser Plugin

Many browsers have plugins that will allow you to make this change without loading your site through a proxy. If you need to test SSL installation or payment gateways, this may be vastly preferred over using third party web proxies.

We recommend the following plugins for Firefox and Chrome, depending on which browser you prefer:

Both plugins require your desired host and your cPanel IP to load it from. Each plugin will have different instructions to use, and may differ based on version.

Editing System Files

Lastly, you may change the host your local computer loads your website from by directly editing your system’s hosts file. This method will be easier if you are an experienced user of the operating system on your local PC.

All operating systems will have a hosts file like our example:

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.

You may deactivate a line to undo this change by prefacing it with a “#” (as in the third line above). This will cause the line to be ignored.

Click the links below to expand specific instructions for how to make this change your desired operating system:

▷ Windows

▷ Mac OS X

▷ UNIX

DNS Flush

Once you have modified your hosts file, it is recommended that you flush your DNS so that the new changes can be implemented more swiftly. DNS flushing must be done using command line. Depending on your computer’s OS, there will be different commands.

LEAVE A REPLY

Please enter your comment!
Please enter your name here