The hosts file allows you to set IP addresses for a domain on your local computer that may override the authoratative 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?.


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.anotherexample.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 eHost 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.

eHost recommends changing your hosts file for development. It provides the most stable development environment. Other methods, including the use of temporary URLs, 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. eHost servers will require you to use the IP address displayed in your cPanel.

You may use the instructions below to look up your IP address:
 
1. Log in to your billing portal.
2. Click My Sites from the left hand menu.
3. Locate the cPanel you wish to point your domain to, and click the Manage button.
4. From inside the cPanel, locate and click the Server Information link in the left hand panel.

If this link is not visible, please click the Expand Stats button to unhide it.

5. Here you can locate your cPanel IP address.

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

⇒ Web Proxy


The fastest and easiest way to change the host you are viewing your domain from is to do so through a webproxy. The following URL is a free service which allows you to load your site from a different host:

http://propagationproxy.com/

To use this web proxy:

1. Enter the domain you wish to view in the Domain Name to Browse textbox.
2. Enter the IP address from your cPanel in the IP Address / Hostname to Request Content From textbox.
3. Click the Browse button.

⇒ 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:

1. Firefox: Change Hosts
2. Chrome: Virtual Hosts

Like the web proxy, the plugins will each 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.anotherexample.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


Windows 8

1. 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 dropdown box in the lower right hand corner that is set to Text Documents (*.txt) and select All Files (*.*)

6. Browse to 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.

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.

9. Save when prompted.

Windows XP and Earlier


1. Browse to Start > Find > Files and Folders.

2. Select the hosts file in your Windows directory (or WINNT\system32\drivers\etc).

3. Verify that the file is not "read only" by right-clicking it, and choosing Properties.

4. Open the file for editing with Notepad.

5. There should already be an entry for "localhost." Earlier versions of Windows have different formats for hosts file entries. Be sure to follow the same format as you find in your file when inserting the eHost IP and the domain name:

On Windows98 and Windows95, the order may be hostname, IP address.
On Windows2000 and WindowsME, the order is IP address, hostname.

6. Make the needed changes and close Notepad.

7. Save when prompted.

You may also need to reboot for the change to take effect. The next time you visit your domain, your browser will try to find the domain at the corresponding IP instead of looking up the IP through DNS.

▽ 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 eHost 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.

▽ UNIX


On Unix-based systems, you can find the hosts file at /etc/hosts. Most distributions of Unix will have terminal located in the same location.

To open the terminal:

1. Go to Menu.
2. Select Applications.
3. Choose Accessories.
4. Select Terminal.

To edit the hosts file:

Unix users can edit hosts files in the same process as Mac users. Please refer to steps 2 through 4 in the Mac section above.

⚫ 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.

0 comments:

Post a Comment

Facebook

Popular Posts

Blog Archive

Total Pageviews