Loading...

Knowledge Base

Previewing websites using HOSTS file.

What is a hosts file?


A hosts file is an address book, situated on your local desktop, that maps a host name to an IP address (network name resolution). Generally, a domain name (host name) is translated in to IP address via the DNS resolution process. However, the host entries that are present in this file will bypass this DNS resolution.
 

Purpose of a hosts file

 
  1. You have modified the Name Servers, and are viewing the cached results due to the DNS propagation delay.
  2. You are in process of migrating the hosting server, and want view the website on the new server when its still under development. This way you can preview the site in the developmental stage, whereas your visitors will continue to view the live website on the old server. Thus, the traffic to your site remains unaffected.
 
 

Flushing Local DNS Cache


You may need to flush your DNS cache as the first step before viewing your website using HOSTS method. Your website's IP address may be saved in your computer's cache. So you need to clear this temporary data so that the IP address you just entered into your hosts file will take effect. To do so:


For Windows OS

 
  • Click your START MENU.
  • Go to ACCESSORIES and then click COMMAND PROMPT.
  • Run the below command:
C:\> ipconfig /flushdns



For Linux OS

 
  • Login into the shell of your machine.
  • Run the below commands:
root@support [~]# cd /etc/rc.d/init.d
root@support [/etc/rc.d/init.d]# ./nscd restart

 


Editing the hosts file

 

To view the results with such immediate effect, you can define a host/domain name in the hosts file.


For Windows

 
  • Go to C:\Windows\System32\drivers\etc and locate the hosts file.
  • Open it in any text editor like Notepad, Notepad++, etc.
  • Add your host entries as shown below and save the file.
111.111.11.11 domain.tld www.domain.tld


For Linux

  • Locate the hosts file at /etc/hosts.
  • Run the below command to edit file: vim /etc/hosts
  • Add your host entries as shown below and save the file.
111.111.11.11 domain.tld www.domain.tld
Did you find this article helpful?

 
* Your feedback is too short

Loading...