Configure Website IP Address in Hosts File

Adding the IP address of a development website to the hosts file allows use of the active domain name.

Many of the CMSs include the domain name within the references added to page and image links. If a development domain is used this will be included in place of the final preferred active domain name.

Although the domain references within the database can be modified subsequently, using the correct domain name to begin with can save this effort and ensure that no lurking references to the temporary domain remain.

Over-writing the global DNS settings for a domain allows for final checks to be made on the new website prior to its launch. Ensuring that aspect of the site respond correctly to the domain name. Care does need to be taken to ensure that referenced files are taken from the correct IP address.

The Hosts File

The hosts file, present on a computer, can be used to countermand the global DNS settings of a domain. The hosts text file comprises a series of rows specifying an IP address and the sub-domain associated with it. The content from a typical Linux hosts file is shown below:

127.0.0.1       localhost
192.168.1.5 nas2.vntweb.co.uk
192.168.1.11 mythtv.vntweb.co.uk
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

The hosts file is a plain text file and should be edited with a plain text editor, for example notepad NOT a word processor such as Word as this is prone to adding additional content.

As can be seen the file comprises a number of lines detailing an IP address and its associated sub-domain.

After making the changes to your hosts file the browser to be used needs to be closed and restarted, for it to adopt the changes made.

Location of Hosts File

It is located in different locations dependant upon the operating system.

  • Linux – /etc/hosts
  • Windows – /Windows/System32/drivers/etc/hosts
  • Mac – /etc/hosts

It doesn’t work

After making the changes to your hosts file, if you find that the change has not been implemented by the browser it may be due to a proxy server between your computer and the Internet.

The proxy server may be within your control, for example as part of an office configuration. Or is may be a part of the configuration made by your ISP.

If your browser accesses the Internet via a proxy server then the configuration of this server will over rule the local settings made in the hosts file.

If possible change your browser to route to the Internet directly.

If the proxy server is a part of your ISPs configuration then it won’t be possible to make use of the local hosts file.

Trojans

Surreptitiously making changes to the computer’s hosts file is used by trojans to redirect website access to illegitimate sites.