BSD Newsletter.com
   Front | Info | Lists | Newsfeeds | Study Guide | What is BSD?
Advertisement: The OpenBSD PF Packet Filter Book: PF for NetBSD, FreeBSD, DragonFly and OpenBSD

BSD Links
·New Links
·Advocacy
·Drivers
·Events
·Flavours
·FAQs
·Guides
·Programming
·Security
·Software
·User Groups

This is the BSDA Study Guide Book written via a wiki collaboration. This is a work in progress. You may contribute to or discuss this specific page at http://bsdwiki.reedmedia.net/wiki/Change_the_order_of_name_resolution.html.

Change the order of name resolution

Concept

Be able to determine the default order of host name resolution on BSD systems and recognize which configuration file controls the order of host name resolution.

Introduction

Most programs (like ping and traceroute) that do a hostname lookup use the gethostbyname(3) or getaddrinfo(3) functions. Commonly the local file /etc/hosts is used first and then normal DNS lookups are done if needed. (The /etc/hosts file is introduced in section TODO.)

Note that ping or telnet can be used to show hostname lookups as the systems sees them.

On NetBSD and FreeBSD, the "name-service switch dispatcher" configured in /etc/nsswitch.conf is used to select which sources for hostname lookups to use and what order to use them. The possible sources are "files" for /etc/hosts, "dns" to use DNS, and "nis" to use NIS (aka "YP"). For example:

$ grep ^hosts /etc/nsswitch.conf
hosts:          files dns

On OpenBSD, the /etc/resolv.conf has an additional "lookup" keyword which defines the ordering of the databases to use, such as "bind" for using DNS (network-based), "file" for searching in /etc/hosts, and "yp" for retrieving from a YP server. If the /etc/resolv.conf file doesn't exist on OpenBSD, then the only the /etc/hosts file is used. If the /etc/resolv.conf file does exist but does not define the "lookup", then the default "lookup" order is: "bind file".

TODO: DragonFly has host.conf and nsswitch.conf -- verify what is used

When using normal DNS lookups, the DNS servers are defined in /etc/resolv.conf. This is covered in section TODO.

Note that a few programs -- like "dig" and "nslookup" -- do the DNS lookups directly because they are more specific.

Examples

Practice Exercises

More information

ping(8), telnet(1), nsswitch.conf(5), resolv.conf(5), host.conf(5)



Front | Information | Lists | Newsfeeds