What you should already know about Hostname Resolution

Author: Jesus Monroy, Jr. (webmaster@svbug.com)
Date: 2001-03-24

Summary

On the Internet, all machines are assigned an IP number. However, humans have a difficult time remembering numbers. As an aide, the system provides name to number translation. The technical wording is hostname resolution. Under BSD UNIX several files and services are used to accomplish this task. The remainder of this article will describe how the system works, what you should know, and where you can get more information. It will not explain how these services work, nor how to configure them. This is just a description.

Default Services

Several programs are available to assist in hostname resolution. Typical such program are started by the script /etc/rc. Those programs include bind (a.k.a. named) and ypserv. By default, niether of these programs are enabled or configured. To enable them durning powering up (or rebooting) you can use /stand/sysinstall. However, it recommended that any person attempting start these services so should read a book on bind and the man pages listed at the end of this article.

On power up, or reboot, /etc/rc defines which services run. On FreeBSD, the default services are enabled via script variables stored in in /etc/defaults/rc.conf. Modification to these services started should be made as delta changes to /etc/rc.conf. Doing so allows the computer to always have a known state that it can be returned to.

How the System Works

When a program, such as web browser, attempts to contact a remote host, it must first get the IP number of the remote host. It does so by first looking in the /etc/hosts file. If it does not find the host name in the file, it then looks at /etc/resolv.conf to see if there is a nameserver listed. If there is, it then uses the IP number listed in the file to contact the bind service on the nameserver. Assuming the nameserver has an answer, the IP for the remote host is return to the program. If not, then the program can try the NIS/YP service. The NIS/YP service, if successful, returns the remote host IP. If not, then the program may return an error of Host Not Found.

In any case, if the hostname resolution fails, then the program will error in some way. That is, if the hosts, bind or nis/yp service(s) fail to find an IP number associated with the hostname, it will return an error.

The order in which the a program searchs for remote host IP number is set by convention to:

  • /etc/hosts
  • /etc/resolv.conf
    • named (bind)
    • NIS/YP
The order maybe changed, or a service may be eliminated, by changing the contents of /etc/host.conf

Other Services

Other services not traditional mentioned or started are TCP Wrappers, rlogin and lp. These services control services. Starting these services should only be done by experienced system administrators, or in a closed, controlled environment. Don't do this if you are connected to the Internet unless you are an experienced system administrator (or can get help).

TCP Wrappers is a daemon program that reports the name of the client host and requested service for incoming connections. It is also capable of denying and/or allowing connections based on a list of IP numbers and/or hostnames. It uses the files /etc/hosts.allow and /etc/hosts.deny. (Note as of recent versions of FreeBSD and TCPWrappers, '/etc/hosts.deny' is no longer used in favor of a new format.)

rlogin has a reverse hostname lookup mechanism. Unlike, the services that use the traditional hosts/bind/yp-nis chain, it does a number authentication. That is, it checks it's internal tables to see if the incoming connection is on a list of approved IP numbers. Only hosts on this list are allowed access, all others are silently refused. A server with this service checks the table at /etc/hosts.equiv. This service allows logins without passwords. This service is intended for maintance work.

lp service, like 'rlogin' does a number authentication. However unlike 'rlogin', lp controls only printer access. The access can be limited to local printer services, but can be expanded to include other printers, include stand-alone network printers.

That does it. Below are links to files I discussed. I recommend you at least read hostname(7), hosts(5) and rc.conf(5).


Concept

hostname(7)

Programs/Services

named aka bind, it is the defacto service used on the Internet
nis BSD version of commercial implementation by Sun Microsystems that offer additional services, like password authentication

Files

/etc/rc.conf system configuration file
/etc/hosts maps numbers to names
/etc/resolv.conf used by resolver(3) to define domain and nameserver
/etc/host.conf - no man page exist, but defines order in which to resolve hostnames

Others

/etc/hosts.allow -- part of tcpwrappers
/etc/hosts.deny -- part of tcpwrappers
/etc/hosts.equiv -- trusted remote host name and user data base (See Also: .rhosts)
/etc/hosts.lpd -- trusted hosts that may use local print services


Terms

  • delta - originally a greek letter meant to signify change. In this case, we mean the original definition of a variable should not be changed. A copy should be made, place in the /etc/rc.conf file, then that copy should be modified.



For questions or comments, please send mail to: webmaster@svbug.com

svbug.com © 30-Apr-2006