Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Installing and Administering Internet Services: HP 9000 Networking > Chapter 2 Installing and Configuring Internet Services

Configuring the Name Service Switch

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

The Name Service Switch determines where your system will look for the information that is traditionally stored in the following files:

  • /etc/hosts

  • /etc/protocols

  • /etc/services

  • /etc/networks

  • /etc/netgroup

  • /etc/rpc

For all types of information except host information, you can configure your system to use NIS (one of the NFS Services), the local /etc file, or both, in any order. For host information, you can configure your system to use BIND (DNS), NIS, the /etc/hosts file, or any combination of the three, in any order.

The default Name Service Switch configuration is adequate for most installations, so you probably do not have to change it. The default configuration is explained in “Default Configuration”.

NOTE: Configuring the Name Service Switch is a separate task from configuring the name services themselves. You must also configure the name services before you can use them. The Name Service Switch just determines which name services are queried and in what order.

The ability to consult more than one name service for host information is often called hostname fallback. The Name Service Switch provides client-side hostname fallback, because it is incorporated into client-side programs (for example, gethostbyname), which request host information.

The Network Information Service (NIS), one of the NFS Services, allows you to configure a server-side hostname fallback. This feature causes the NIS server to query BIND when it fails to find requested host information in its database. The NIS server then returns the host information to the client through NIS. This server-side hostname fallback is intended for use with clients like PCs that do not have a feature like the Name Service Switch. Hewlett-Packard recommends that you use the Name Service Switch if possible, instead of the server-side hostname fallback provided by NIS. For more information on the NIS server-side hostname fallback, see Installing and Administering NFS Services.

You can use SAM to configure the Name Service Switch. Type sam at the HP-UX prompt.

Following are some suggestions for customizing your Name Service Switch configuration:

  • If you want your system to consult the local /etc/netgroup file when it fails to find a netgroup in the NIS netgroup database, create or modify the netgroup line in the /etc/nsswitch.conf file as follows:

    netgroup: nis [NOTFOUND=continue] files 

  • If you want your system to consult BIND (DNS) when it fails to find a host name in NIS, create or modify the hosts line in the /etc/nsswitch.conf file as follows:

    hosts: nis [NOTFOUND=continue] dns files 

    With this configuration, if NIS does not contain the requested information, and BIND is not configured, the /etc/hosts file is consulted.

  • If you want your system to consult NIS if it fails to find a host name in BIND or if the BIND name servers are not responding, create or modify the hosts line in the /etc/nsswitch.conf file as follows:

    hosts: dns [NOTFOUND=continue TRYAGAIN=continue] nis files 

    With this configuration, if BIND does not return the requested information, and NIS is not running, the /etc/hosts file is consulted.

HP recommends that you maintain at least a minimal /etc/hosts file that includes important addresses like gateways, diskless boot servers and root servers, and your host's own IP address. HP also recommends that you include the word files in the hosts line to help ensure a successful system boot using the /etc/hosts file when BIND and NIS are not available.

CAUTION: Changing the default configuration can complicate troubleshooting. The default configuration is designed to preserve the authority of the name service you are using. It switches from BIND to NIS only if BIND is not enabled. It switches from NIS to the local /etc file only if NIS is not enabled. It is very difficult to diagnose problems when multiple name servers are configured and enabled for use.

Default Configuration

A default nsswitch.conf file is supplied in the /usr/newconfig/etc directory. It contains the following lines:


hosts:     dns  nis  files

protocols: nis  files

services:  nis  files

networks:  nis  files

netgroup:  nis  files

rpc:       nis  files 

This is the default configuration. In other words, if you copy /usr/newconfig/etc/nsswitch.conf to /etc/nsswitch.conf, the Name Service Switch behaves the same way it would if no /etc/nsswitch.conf file existed.

Figure 2-1 “Default Behavior of the Name Service Switch” illustrates the default behavior of the Name Service Switch for host information lookups.

Figure 2-1 Default Behavior of the Name Service Switch

Default Behavior of the Name Service Switch

The /etc/nsswitch.conf File

The configuration file for the Name Service Switch is /etc/nsswitch.conf, which consists of lines with the following syntax:

info_type: source [status=action status=action...] source ... 

Table 2-1 “Values for Variables in the /etc/nsswitch.conf File” displays the possible values for each variable.

Table 2-1 Values for Variables in the /etc/nsswitch.conf File

info_type

A type of configuration information. Possible values are as follows:

hosts

Host names and IP addresses, as in /etc/hosts.

protocols

Protocol names and numbers, as in /etc/protocols.

services

Service names, port numbers, and protocols, as in /etc/services.

networks

Network names and IP addresses, as in /etc/networks.

netgroup

NFS netgroup names and members, as in /etc/netgroup.

rpc

RPC program names and numbers, as in /etc/rpc.

source

A name service where information can be found. Possible values are as follows:

dns

Berkeley Internet Name Domain (BIND), the Berkeley implementation of the Domain Name System (DNS).

nis

The Network Information Service (NIS), one of the NFS Services.

files

The appropriate /etc file (/etc/hosts, /etc/services, etc.).

status

The result of querying the source. Possible values are as follows:

SUCCESS

The query was successful, and the information was found.

NOTFOUND

The source responded to the query, indicating that it did not have the requested information.

UNAVAIL

The query failed, because the source is not configured on your local system, or because the server system is not running the name service.

TRYAGAIN

The query failed or timed out because the server system is not responding.

action

The action to be taken based on the status of the query. Possible values are as follows:

return

End the search and return control to the calling process, without querying the next source in the list.

continue

Continue the search by querying the next source in the list.

 

If you specify any status=action pairs, the set of status=action pairs for each source must be enclosed in square brackets [ ].

If the /etc/nsswitch.conf file does not exist, or if no source is specified in it, the default search order is as follows:

  1. DNS (for host information only)

  2. NIS

  3. local /etc file

The default status=action pairs are as follows:

  • SUCCESS=return

  • NOTFOUND=return

  • UNAVAIL=continue

  • TRYAGAIN=return

The default search order for host information is shown in Figure 2-1 “Default Behavior of the Name Service Switch”.

For more information on the Name Service Switch, type man 4 switch at the HP-UX prompt.

To Check the Syntax of the hosts Line

To check the syntax of the hosts line in /etc/nsswitch.conf file, start nslookup with the swdebug option, as follows:

nslookup -swdebug 

You will see the output of the parser as it reads the hosts line in your nsswitch.conf file. If your hosts line is syntactically correct, you will see the line __nsw_getconfig: PARSE SUCCESSFUL. If your hosts line contains a syntax error, you will see the line __nsw_getconfig: ERR-SYNTAX ERROR.

The following example checks the syntax of a hosts line that is missing a closing square bracket:


# cat /etc/nsswitch.conf

hosts: dns [notfound=continue] nis [notfound=continue files



# nslookup -swdebug

__nsw[/etc/nsswitch.conf] 1->hosts: dns [notfound=continue] nis [notf

ound=continue files

__nsw[/etc/nsswitch.conf]LS->L<hosts>L<:>L<dns>L<[>L<notfound>L<=>L<c

ontinue>L<]>L<nis>L<[>L<notfound>L<=>L<continue>L<files>^Missing =^

__nsw.error_recovery: ERR- Error Recovery Completed

__nsw_getconfig: ERR- SYNTAX ERROR

__nsw_getdefault: default hosts lookup policy

Default Name Server:  hpindbu.cup.hp.com

The parser indicates the error with carats (^). In this case, the parser reads the word files as another status following notfound=continue, because it has not encountered a closing square bracket. If the word files were a status, it must be followed by an equal sign, and it is not. So the parser displays the message ^Missing =^.

NOTE: The parser checks only the position of the elements with respect to the delimiters :, [, and ]. It does not check the spelling of all the elements. For example, if you type dsn instead of dns, you receive the PARSE SUCCESSFUL message. However, when you attempt a host name lookup, dsn is not a known name service, so DNS is not queried, and the lookup switches to the next configured source.

To Check the Current hosts Configuration

To check the Name Service Switch configuration that your system is currently using for host information, start nslookup and issue the policy command, as follows:

# nslookup

> policy

The output for the default configuration is as follows:


# Lookups = 3

dns [RRCR]     nis [RRCR]     files [RRRR]

The letters in square brackets stand for (R)eturn or (C)ontinue. They represent the values of the four status values, SUCCESS, NOTFOUND, UNAVAIL, and TRYAGAIN. In the example, the status=action pairs configured for dns and nis are

  • SUCCESS=return

  • NOTFOUND=return

  • UNAVAIL=continue

  • TRYAGAIN=return

For the following hosts line

hosts:  dns [NOTFOUND=continue]  files

the policy command displays the following:

# Lookups = 2

dns [RCCR]     files [RRRR]

To stop the nslookup program, type exit.

To Trace a Host Name Lookup

To trace a host name lookup, start nslookup, set the swtrace option, and perform a lookup, as follows:

# nslookup

> set swtrace

> hostname

For the nsswitch.conf file containing the hosts line

hosts: dns [NOTFOUND=continue] nis [NOTFOUND=continue] files

the following example tries all three name services before it finds an answer:

# nslookup

> set swtrace

> romney

Name Server: hpindbu.cup.hp.com

Address: 15.13.104.13



lookup source is DNS

Name Server: hpindbu.cup.hp.com

Address: 15.13.104.13



*** hpindbu.cup.hp.com can't find romney: Non-existent domain



Switching to next source in the policy

lookup source is NIS

Default NIS Server: hpntc43c

Address: 15.13.119.52

Aliases: hpntc43c.cup.hp.com, hpntc43c-119, 3c-119



*** No address information is available for "romney"



Switching to next source in the policy

lookup source is FILES

Using /etc/hosts on: hpntc2k

Name: romney

Address: 15.13.104.128

NOTE: If you do not set swtrace, nslookup displays only the first name service where it looks for a host, even if it finds the host in another name service.
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1996 Hewlett-Packard Development Company, L.P.