DNS and hosts file

What is DNS

 TCP/IP networks communicate using numbers called IP addresses. However, when we surf the net or email, we rarely enter IP addresses.

 To access the Internet, enter a URL such as "www.yahoo.co.jp", and also specify the address in the form of "aaa@bbb.com" for e-mail.

 In the world of TCP/IP, you should be able to communicate without using an IP address such as "192.168.1.10", so why is communication possible?

 This is because there is a name resolution mechanism called DNS (Domain Name System). This is because the IP address can be obtained from DNS even if the name using alphabets and numbers is used. This IP address is used to identify the other party.

DNS provides a mechanism for mapping IP addresses and host names and resolving IP addresses from host names.

 In early networks, unlike the Internet, there was no need to consider the participation of an unspecified number of people, and the scale of the network was small, so each client managed its own hosts file. The hosts file is a list of mappings of host names and IP addresses.

 However, when it comes to the scale of the Internet, it is not realistic to have each host have name resolution information. This is because an unspecified number of hosts participate in the Internet.

 The hosts file must be rewritten each time the number of connected devices increases, and the hosts file must be rewritten each time the IP address of the host changes. This would be a daunting task and would overwhelm the user.

 For this reason, currently, a system is adopted in which a dedicated DNS server for name resolution is installed and the mapping between IP addresses and host names is centrally managed.

Using DNS has the following advantages:

  • (1) It can be accessed with a name that is easy for humans to remember. No need to remember hard-to-remember IP address numbers.
  • (2) The IP address of the host can be changed without notifying the user.
  • (3) Users no longer need to define the hosts file.

These benefits make DNS an integral part of modern networks.

hosts file

 In early networks, unlike the Internet, there was no need to consider the participation of an unspecified number of people, and the scale of the network was small, so each client had its own name resolution mechanism.

The mechanism is to perform name resolution locally by defining the mapping between IP address and host name in the hosts file.

The location where the hosts file exists depends on the OS.

OSLocation of the hosts file
UNIX/etc/hosts
Windows XP/Vista/7/8C:\WINDOWS\system32\drivers\etc\hosts
Windows 2000C:\WINNT\system32\drivers\etc\hosts
Windows 95/98/MEC:\Windows\hosts

Write the hosts file like this:

 [IP address] [official host name] [alias name]

For example, to call the computer whose address is 192.168.1.1 with www1.xxx.or.jp and www1, write as follows.

192.168.1.1 www1.xxx.or.jp www1

Example of hosts file (Windows)


# Copyright (c) 1993-2006 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
192.168.1.1     www1.xxx.or.jp  www1
192.168.1.2     www2.xxx.or.jp  www2
192.168.1.3     www3.xxx.or.jp  www3

There are disadvantages to managing host names and IP addresses in the hosts file.

 The hosts file must be rewritten each time the number of connected devices increases, and the hosts file must be rewritten each time the IP address of the host changes. This would be a daunting task and would overwhelm the user.

For this reason, the method using the hosts file is not used much nowadays.