Hosts file

From WebHost Wiki

Jump to: navigation, search

The hosts file allows you to find computers on a network (eg the internet) without relying on DNS. This can be useful for a number of reasons, for example to test your web site before your domain name has propagated around the internet.

hosts is a plain text file that maps hostnames to IP addresses. This file is (unlike DNS) under the control of the user who is using the computer.

Contents

What it looks like

The hosts file will look something like this on a Windows computer:

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost

On a default Ubuntu installation it will look like this:

127.0.0.1 localhost.localdomain localhost ubuntu

# 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
ff02::3 ip6-allhosts

Location of the hosts file

  • On a Windows-based system, the hosts file is usually found in C:\WINDOWS\system32\drivers\etc
  • On a UNIX-compliant system you would find the hosts file at /etc/hosts.

Making changes to your hosts file

Open the file named "hosts" with a text editor, and simply add another entry at the end.

For example, if your domain name is www.fred.com and your server is Palmer (whose IP Address is 203.145.38.90), you would enter the following:

203.145.38.90   www.fred.com

Or to have anything that has fred.com as the last part of the hostname:

203.145.38.90   .fred.com

Once you have done this, all requests for www.fred.com from your computer will not query a DNS server, instead they will go directly to the IP address specified. Because it will not try to contact a DNS server it will speed up the accessing time.

NOTE: When saving the hosts file, make sure you don't include any file extension - hosts.txt (if Notepad wants to add an extension, select Save as type "All files", not "Text Documents").


See also

Personal tools