Name Resolution
The process of obtaining an Internet address from a host name is known as name resolution and is done by the gethostbyname subroutine.
The process of translating an Internet address into a host name is known as reverse name resolution and is done by the gethostbyaddr subroutine.
When a process receives a symbolic host name and needs to resolve it into an address, it calls a resolver routine.
- BIND/DNS (domain name server, named)
- Network Information Service (NIS)
- Local /etc/hosts file
To resolve a name in a domain network, the resolver routine first queries the domain name server database, which may be local if the host is a domain name server or may be on a foreign host. Name servers translate domain names into Internet addresses. The group of names for which a name server is responsible is its zone of authority. If the resolver routine is using a remote name server, the routine uses the Domain Name Protocol (DOMAIN) to query for the mapping. To resolve a name in a flat network, the resolver routine checks for an entry in the local /etc/hosts file. When NIS is used, the /etc/hosts file on the master server is checked.
By default, resolver routines attempt to resolve names using the above resources. BIND/DNS will be tried first. If the /etc/resolv.conf file does not exist or if BIND/DNS could not find the name, NIS is queried if it is running. If NIS is not running, then the local /etc/hosts file is searched. If none of these services could find the name then the resolver routines return with HOST_NOT_FOUND. If all of the services were unavailable, then the resolver routines return with SERVICE_UNAVAILABLE.
The default order can be overwritten by creating the configuration file, /etc/netsvc.conf and specifying the desired order. Both the default and /etc/netsvc.conf can be overwritten with the environment variable NSORDER. If either the /etc/netsvc.conf file or environment variable NSORDER are defined, then at least one value must be specified along with the option.
hosts = value,value,value
where value is one of the listed sources.
NSORDER=value,value,value
The order is specifed on one line with values separated by commas. White spaces are permitted between the commas and the equal sign. The values specified and their ordering depends on the network configuration. For example, if the local network is organized as a flat network, then only the /etc/hosts file is needed.
hosts=local
NSORDER=local
If the local network is a domain network using a name server for name resolution and an /etc/hosts file for backup, then both services should be specified.
hosts=bind,local
NSORDER=bind,local
- current service is not running, therefore, it is unavailable
- current service could not find the name and is not authoritative.
If the /etc/resolv.conf file does not exist, then BIND/DNS is considered to be not set up or running and therefore not available. If the subroutines, getdomainname and yp_bind fail, then it is assumed that the NIS service is not set up or running and therefore not available. If the /etc/hosts file could not be opened, then a local search is impossible and therefore the file and service are unavailable.
A service listed as authoritative means that it is the expert of its successors and should have the information requested. (The other services may contain only a subset of the information in the authoritative service.) Name resolution will end after trying a service listed as authoritative even if it does not find the name. If an authoritative service is not available, then the next service specified will be queried, otherwise the resolver routine will return with HOST_NOT_FOUND.
hosts = nis=auth,bind,local
If NIS is running, then search is ended after the NIS query regardless of whether the name was found. If NIS is not running, then the next source is queried, which is BIND.
TCP/IP name servers use caching to reduce the cost of searching for names of hosts on remote networks. Instead of searching anew for a host name each time a request is made, a name server looks at its cache to see if the host name was resolved recently. Because domain and host names do change, each item remains in the cache for a limited length of time specified by the record's time to live (TTL). In this way, authorities can specify how long they expect the name resolution to be accurate.
host.subdomain.subdomain.rootdomain
If the host name is not set up as a fully qualified domain name, and if the system is set up to use a DOMAIN name server in conjunction with the sendmail program, the sendmail configuration file (/etc/sendmail.cf) must be edited to reflect this official host name. In addition, the domain name macros in this configuration file must be set for the sendmail program to operate correctly.
For a host that is in a domain network but is not a name server, the local domain name and domain name server are specified in the /etc/resolv.conf file. In a domain name server host, the local domain and other name servers are defined in files read by the named daemon when it starts.