Skip to main content
Engineering LibreTexts

10-D.6: Name Resolution

  • Page ID
    40590
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    Name Resolution

    Name resolution is a process of converting an IP address to a user friendly computer name. Originally networks used host files to resolve names to IP addresses. These files were a text file that the computer consulted if a name lookup was necessary. All the computers on the network and their IP address mappings had to be entered manually into these files. The file was then automatically copied to all the other machines on the network. When a resource was required, by the user typing its name, the machine referred to the host file to find the IP address.

    As networks got larger and larger the text based hosts file grew too large and required too much maintenance. Then came the advent of dynamically assigned IP addresses. IP to name resolution took on a transitory nature with the possibility of IP addresses changing on a weekly basis. The days of the host files were numbered as the primary tool of name resolution.

    The /etc/hosts File

    The computer file hosts is a file that maps hostnames to IP addresses. It is a plain text file. Originally a file named HOSTS.TXT was manually maintained and made available via file sharing. It contains the hostnames and address of hosts as contributed for inclusion by member organizations. The Domain Name System, first described in 1983 and implemented in 1984, automated the publication process and provided instantaneous and dynamic hostname resolution in the rapidly growing network. In modern operating systems, the hosts file remains an alternative name resolution mechanism, configurable often as part of facilities such as the Name Service Switch as either the primary method or as a fallback method.

    The format of the file is quite simple: an IP address, followed by a hostname. In the following example the first entry is the local loopback entry - in IPv4 and then IPv6 format; then the entry for pbmac-server, which has no domain portion of the hostname; and then the entry for www.google.com - which includes the google.com domain. In this case it is assumed the pbmac-server is on the local domain.

    pbmac@pbmac-server $ cat /etc/hosts
    127.0.0.1  localhost loopback
    ::1        localhost
    192.168.0.1    pbmac-server
    172.217.6.78   www.googlecom
    

    The /etc/resolv.conf File

    The /etc/resolv.conf is a resolver configuration file for Linux. It is used to configure the domain name servers for a particular host. The file /etc/resolv.conf file contains information that is read by the resolver routines the first time they are invoked by a process. The file is designed to be human readable and contains a list of keywords with values that provide various types of resolver information.

    The file is simply a keyword, followed by an IP address. The IP address points to the DNS server that handles ALL of the name resolutions that are not provided in the /etc/hosts file.

    pbmac@pbmac-server $ cat /etc/resolv.conf
    nameserver 10.0.80.11
    nameserver 10.0.80.12

    The /etc/nsswitch.conf File

    A system administrator usually configures the operating system's name services using the file /etc/nsswitch.conf. This file lists databases (such as passwd, shadow and group) and one or more sources for obtaining that information. Examples for sources are files for local files, ldap for the Lightweight Directory Access Protocol, nis for the Network Information Service, nisplus for NIS+, and wins for Windows Internet Name Service.

    The nsswitch.conf file has line entries for each service consisting of a database name in the first field, terminated by a colon, and a list of possible source databases mechanisms in the second field. A typical file might look like:

    pbmac@pbmac-server $ cat /etc/nsswitch.conf
    passwd:     files ldap
    shadow:     files
    group:      files ldap
    
    hosts:      files dns

    The order of the services listed determines in which order NSS will attempt to use those services to resolve queries on the specified database. In the above example the name resolution uses the /etc/hosts file first, and if that does not provide a resolution, then the system consults the DNS server at the IP address shown in the /etc/resolv.conf file.

    Adapted From:
    "hosts (file)" by Multiple ContributorsWikipedia is licensed under CC BY-SA 3.0
    "/etc/resolv.conf" by Multiple contributors, Cyberciti.biz is licensed under CC BY-NC-SA 3.0"
    Name Service Switch"
     by Multiple ContributorsWikipedia is licensed under CC BY-SA 3.0


    10-D.6: Name Resolution is shared under a CC BY-NC license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?