The Linux NIS(YP)/NYS/NIS+ HOWTO

Thorsten Kukuk

v1.2, 4 August 2002


Table of Contents
1. Introduction
1.1. New Versions of this Document
1.2. Disclaimer
1.3. Feedback and Corrections
1.4. Acknowledgements
2. Glossary and General Information
2.1. Glossary of Terms
2.2. Some General Information
3. NIS, NYS or NIS+ ?
3.1. libc 4/5 with traditional NIS or NYS ?
3.2. glibc 2 and NIS/NIS+
3.3. NIS or NIS+ ?
4. How it works
4.1. How NIS works
4.2. How NIS+ works
5. The RPC Portmapper
6. What do you need to set up NIS?
6.1. Determine whether you are a Server, Slave or Client.
6.2. The Software
7. Setting Up the NIS Client
7.1. The ypbind daemon
7.2. Setting up a NIS Client using Traditional NIS
7.3. Setting up a NIS Client using NYS
7.4. Setting up a NIS Client using glibc 2.x
7.5. The nsswitch.conf File
7.6. Shadow Passwords with NIS
8. What do you need to set up NIS+ ?
8.1. The Software
8.2. Setting up a NIS+ client
8.3. NIS+, keylogin, login and PAM
8.4. The nsswitch.conf File
9. Setting up a NIS Server
9.1. The Server Program ypserv
9.2. The Server Program yps
9.3. The Program rpc.ypxfrd
9.4. The Program rpc.yppasswdd
10. Verifying the NIS/NYS Installation
11. Creating and Updating NIS maps
11.1. Creating new NIS maps
11.2. Updating NIS maps
11.3. Length of Map entries
12. Surviving a Reboot
12.1. NIS Init Script
12.2. NIS Domain Name
12.3. Distribution-specific Issues
13. Common Problems and Troubleshooting NIS
14. Frequently Asked Questions

1. Introduction

More and more, Linux machines are installed as part of a network of computers. To simplify network administration, most networks (mostly Sun-based networks) run the Network Information Service. Linux machines can take full advantage of existing NIS service or provide NIS service themselves. Linux machines can also act as full NIS+ clients, this support is in beta stage.

This document tries to answer questions about setting up NIS(YP) and NIS+ on your Linux machine. Don't forget to read Section 5.

The NIS-Howto is edited and maintained by

        Thorsten Kukuk, <kukuk@suse.de>

The primary source of the information for the initial NIS-Howto was from:

Andrea Dell'Amico       <adellam@ZIA.ms.it>
Mitchum DSouza          <Mitch.DSouza@NetComm.IE>
Erwin Embsen            <erwin@nioz.nl>
Peter Eriksson          <peter@ifm.liu.se>

who we should thank for writing the first versions of this document.


1.1. New Versions of this Document

You can always view the latest version of this document on the World Wide Web via the URL http://www.linux-nis.org/nis-howto/HOWTO/NIS-HOWTO.html.

New versions of this document will also be uploaded to various Linux WWW and FTP sites, including the LDP home page.

Links to translations of this document could be found at http://www.linux-nis.org/nis-howto/.


1.3. Feedback and Corrections

If you have questions or comments about this document, please feel free to mail Thorsten Kukuk, at kukuk@linux-nis.org. I welcome any suggestions or criticisms. If you find a mistake with this document, please let me know so I can correct it in the next version. Thanks.

Please do not mail me questions about special problems with your Linux Distribution! I don't know every Linux Distribution. But I will try to add every solution you send me.


2. Glossary and General Information

2.1. Glossary of Terms

In this document a lot of acronyms are used. Here are the most important acronyms and a brief explanation:

DBM

DataBase Management, a library of functions which maintain key-content pairs in a data base.

DLL

Dynamically Linked Library, a library linked to an executable program at run-time.

domainname

A name "key" that is used by NIS clients to be able to locate a suitable NIS server that serves that domainname key. Please note that this does not necessarily have anything at all to do with the DNS "domain" (machine name) of the machine(s).

FTP

File Transfer Protocol, a protocol used to transfer files between two computers.

libnsl

Name services library, a library of name service calls (getpwnam, getservbyname, etc...) on SVR4 Unixes. GNU libc uses this for the NIS (YP) and NIS+ functions.

libsocket

Socket services library, a library for the socket service calls (socket, bind, listen, etc...) on SVR4 Unixes.

NIS

Network Information Service, a service that provides information, that has to be known throughout the network, to all machines on the network. There is support for NIS in Linux's standard libc library, which in the following text is referred to as "traditional NIS".

NIS+

Network Information Service (Plus :-), essentially NIS on steroids. NIS+ is designed by Sun Microsystems Inc. as a replacement for NIS with better security and better handling of _large_ installations.

NYS

This is the name of a project and stands for NIS+, YP and Switch and is managed by Peter Eriksson <peter@ifm.liu.se>. It contains among other things a complete reimplementation of the NIS (= YP) code that uses the Name Services Switch functionality of the NYS library.

NSS

Name Service Switch. The /etc/nsswitch.conf file determines the order of lookups performed when a certain piece of information is requested.

RPC

Remote Procedure Call. RPC routines allow C programs to make procedure calls on other machines across the network. When people talk about RPC they most often mean the Sun RPC variant.

YP

Yellow Pages(tm), a registered trademark in the UK of British Telecom plc.

TCP-IP

Transmission Control Protocol/Internet Protocol. It is the data communication protocol most often used on Unix machines.


3. NIS, NYS or NIS+ ?


4. How it works

4.1. How NIS works

Within a network there must be at least one machine acting as a NIS server. You can have multiple NIS servers, each serving different NIS "domains" - or you can have cooperating NIS servers, where one is the master NIS server, and all the other are so-called slave NIS servers (for a certain NIS "domain", that is!) - or you can have a mix of them...

Slave servers only have copies of the NIS databases and receive these copies from the master NIS server whenever changes are made to the master's databases. Depending on the number of machines in your network and the reliability of your network, you might decide to install one or more slave servers. Whenever a NIS server goes down or is too slow in responding to requests, a NIS client connected to that server will try to find one that is up or faster.

NIS databases are in so-called DBM format, derived from ASCII databases. For example, the files /etc/passwd and /etc/group can be directly converted to DBM format using ASCII-to-DBM translation software (makedbm, included with the server software). The master NIS server should have both, the ASCII databases and the DBM databases.

Slave servers will be notified of any change to the NIS maps, (via the yppush program), and automatically retrieve the necessary changes in order to synchronize their databases. NIS clients do not need to do this since they always talk to the NIS server to read the information stored in it's DBM databases.

Old ypbind versions do a broadcast to find a running NIS server. This is insecure, due the fact that anyone may install a NIS server and answer the broadcast queries. Newer Versions of ypbind (ypbind-3.3 or ypbind-mt) are able to get the server from a configuration file - thus no need to broadcast.


5. The RPC Portmapper

To run any of the software mentioned below you will need to run the program /usr/sbin/portmap. Some Linux distributions already have the code in the /sbin/init.d/ or /etc/rc.d/ files to start up this daemon. All you have to do is to activate it and reboot your Linux machine. Read your Linux Distribution Documentation how to do this.

The RPC portmapper (portmap(8)) is a server that converts RPC program numbers into TCP/IP (or UDP/IP) protocol port numbers. It must be running in order to make RPC calls (which is what the NIS/NIS+ client software does) to RPC servers (like a NIS or NIS+ server) on that machine. When an RPC server is started, it will tell portmap what port number it is listening to, and what RPC program numbers it is prepared to serve. When a client wishes to make an RPC call to a given program number, it will first contact portmap on the server machine to determine the port number where RPC packets should be sent.

Since RPC servers could be started by inetd(8), portmap should be running before inetd is started.

For secure RPC, the portmapper needs the Time service. Make sure, that the Time service is enabled in /etc/inetd.conf on all hosts:
#
# Time service is used for clock syncronization.
#
time    stream  tcp     nowait  root    internal
time    dgram   udp     wait    root    internal

IMPORTANT: Don't forget to restart inetd after changes on its configuration file !


6. What do you need to set up NIS?


7. Setting Up the NIS Client

7.1. The ypbind daemon

After you have succesfully compiled the software you are now ready to install it. A suitable place for the ypbind daemon is the directory /usr/sbin. Some people may tell you that you don't need ypbind on a system with NYS. This is wrong. ypwhich and ypcat need it always.

You must do this as root of course. The other binaries (ypwhich, ypcat, yppasswd, yppoll, ypmatch) should go in a directory accessible by all users, normally /usr/bin.

Newer ypbind versions have a configuration file called /etc/yp.conf. You can hardcode a NIS server there - for more info see the manual page for ypbind(8). You also need this file for NYS. An example:
  ypserver 10.10.0.1
  ypserver 10.0.100.8
  ypserver 10.3.1.1

If the system can resolve the hostnames without NIS, you may use the name, otherwise you have to use the IP address. ypbind 3.3 has a bug and will only use the last entry (ypserver 10.3.1.1 in the example). All other entries are ignored. ypbind-mt handle this correct and uses that one, which answerd at first.

It might be a good idea to test ypbind before incorporating it in the startup files. To test ypbind do the following:

At this point you should be able to use NIS client programs like ypcat, etc... For example, ypcat passwd.byname will give you the entire NIS password database.

IMPORTANT: If you skipped the test procedure then make sure you have set the domain name, and created the directory

    /var/yp

This directory MUST exist for ypbind to start up succesfully.

To check if the domainname is set correct, use the /bin/ypdomainname from yp-tools 2.2. It uses the yp_get_default_domain() function which is more restrict. It doesn't allow for example the "(none)" domainname, which is the default under Linux and makes a lot of problems.

If the test worked you may now want to change your startupd files so that ypbind will be started at boot time and your system will act as a NIS client. Make sure that the domainname will be set before you start ypbind.

Well, that's it. Reboot the machine and watch the boot messages to see if ypbind is actually started.


7.5. The nsswitch.conf File

The Network Services switch file /etc/nsswitch.conf determines the order of lookups performed when a certain piece of information is requested, just like the /etc/host.conf file which determines the way host lookups are performed. For example, the line

    hosts: files nis dns

specifies that host lookup functions should first look in the local /etc/hosts file, followed by a NIS lookup and finally through the domain name service (/etc/resolv.conf and named), at which point if no match is found an error is returned. This file must be readable for every user! You can find more information in the man-page nsswitch.5 or nsswitch.conf.5.

A good /etc/nsswitch.conf file for NIS is:
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
#	nisplus			Use NIS+ (NIS version 3)
#	nis			Use NIS (NIS version 2), also called YP
#	dns			Use DNS (Domain Name Service)
#	files			Use the local files
#	db			Use the /var/db databases
#	[NOTFOUND=return]	Stop searching if not found so far
#

passwd:     compat
group:      compat
# For libc5, you must use shadow: files nis
shadow:     compat

passwd_compat: nis
group_compat: nis
shadow_compat: nis

hosts:      nis files dns

services:   nis [NOTFOUND=return] files
networks:   nis [NOTFOUND=return] files
protocols:  nis [NOTFOUND=return] files
rpc:        nis [NOTFOUND=return] files
ethers:     nis [NOTFOUND=return] files
netmasks:   nis [NOTFOUND=return] files
netgroup:   nis
bootparams: nis [NOTFOUND=return] files
publickey:  nis [NOTFOUND=return] files
automount:  files
aliases:    nis [NOTFOUND=return] files

passwd_compat, group_compat and shadow_compat are only supported by glibc 2.x. If there are no shadow rules in /etc/nsswitch.conf, glibc will use the passwd rule for lookups. There are some more lookup module for glibc like hesoid. For more information, read the glibc documentation.


7.6. Shadow Passwords with NIS

Shadow passwords over NIS are always a bad idea. You loose the security, which shadow gives you, and it is supported by only some few Linux C Libraries. A good way to avoid shadow passwords over NIS is, to put only the local system users in /etc/shadow. Remove the NIS user entries from the shadow database, and put the password back in passwd. So you can use shadow for the root login, and normal passwd for NIS user. This has the advantage that it will work with every NIS client.


8. What do you need to set up NIS+ ?


8.4. The nsswitch.conf File

The Network Services switch file /etc/nsswitch.conf determines the order of lookups performed when a certain piece of information is requested, just like the /etc/host.conf file which determines the way host lookups are performed. For example, the line

    hosts: files nisplus dns

specifies that host lookup functions should first look in the local /etc/hosts file, followed by a NIS+ lookup and finally through the domain name service (/etc/resolv.conf and named), at which point if no match is found an error is returned.

A good /etc/nsswitch.conf file for NIS+ is:
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
#	nisplus			Use NIS+ (NIS version 3)
#	nis			Use NIS (NIS version 2), also called YP
#	dns			Use DNS (Domain Name Service)
#	files			Use the local files
#	db			Use the /var/db databases
#	[NOTFOUND=return]	Stop searching if not found so far
#

passwd:     compat
group:      compat
shadow:     compat

passwd_compat: nisplus
group_compat:  nisplus
shadow_compat: nisplus

hosts:      nisplus files dns

services:   nisplus [NOTFOUND=return] files
networks:   nisplus [NOTFOUND=return] files
protocols:  nisplus [NOTFOUND=return] files
rpc:        nisplus [NOTFOUND=return] files
ethers:     nisplus [NOTFOUND=return] files
netmasks:   nisplus [NOTFOUND=return] files
netgroup:   nisplus
bootparams: nisplus [NOTFOUND=return] files
publickey:  nisplus
automount:  files
aliases:    nisplus [NOTFOUND=return] files


9. Setting up a NIS Server

9.1. The Server Program ypserv

This document only describes how to set up the "ypserv" NIS server.

The NIS server software can be found on:

  Site               Directory                    File Name

  ftp.kernel.org     /pub/linux/utils/net/NIS     ypserv-2.4.tar.gz
  ftp.kernel.org     /pub/linux/utils/net/NIS     ypserv-2.4.tar.bz2

You could also look at http://www.linux-nis.org/nis/ for more information.

The server setup is the same for both traditional NIS and NYS.

Compile the software to generate the ypserv and makedbm programs. ypserv-2.x only supports the securenets file for access restrictions.

If you run your server as master, determine what files you require to be available via NIS and then add or remove the appropriate entries to the "all" rule in /var/yp/Makefile. You always should look at the Makefile and edit the Options at the beginning of the file.

There was one big change between ypserv 1.1 and ypserv 1.2. Since version 1.2, the file handles are cached. This means you have to call makedbm always with the -c option if you create new maps. Make sure, you are using the new /var/yp/Makefile from ypserv 1.2 or later, or add the -c flag to makedbm in the Makefile. If you don't do that, ypserv will continue to use the old maps, and not the updated one.

Now edit /var/yp/securenets and /etc/ypserv.conf. For more information, read the ypserv(8) and ypserv.conf(5) manual pages.

Make sure the portmapper (portmap(8)) is running, and start the server ypserv. The command

    % rpcinfo -u localhost ypserv

should output something like

    program 100004 version 1 ready and waiting
    program 100004 version 2 ready and waiting

The "version 1" line could be missing, depending on the ypserv version and configuration you are using. It is only necessary if you have old SunOS 4.x clients.

Now generate the NIS (YP) database. On the master, run

    % /usr/lib/yp/ypinit -m

On a slave make sure that ypwhich -m works. This means, that your slave must be configured as NIS client before you could run
    % /usr/lib/yp/ypinit -s masterhost
to install the host as NIS slave.

That's it, your server is up and running.

If you have bigger problems, you could start ypserv and ypbind in debug mode on different xterms. The debug output should show you what goes wrong.

If you need to update a map, run make in the /var/yp directory on the NIS master. This will update a map if the source file is newer, and push the files to the slave servers. Please don't use ypinit for updating a map.

You might want to edit root's crontab *on the slave* server and add the following lines:

      20 *    * * *    /usr/lib/yp/ypxfr_1perhour
      40 6    * * *    /usr/lib/yp/ypxfr_1perday
      55 6,18 * * *    /usr/lib/yp/ypxfr_2perday
This will ensure that most NIS maps are kept up-to-date, even if an update is missed because the slave was down at the time the update was done on the master.

You can add a slave at every time later. At first, make sure that the new slave server has permissions to contact the NIS master. Then run
    % /usr/lib/yp/ypinit -s masterhost
on the new slave. On the master server, add the new slave server name to /var/yp/ypservers and run make in /var/yp to update the map.

If you want to restrict access for users to your NIS server, you'll have to setup the NIS server as a client as well by running ypbind and adding the plus-entries to /etc/passwd _halfway_ the password file. The library functions will ignore all normal entries after the first NIS entry, and will get the rest of the info through NIS. This way the NIS access rules are maintained. An example:

     root:x:0:0:root:/root:/bin/bash
     daemon:*:1:1:daemon:/usr/sbin:
     bin:*:2:2:bin:/bin:
     sys:*:3:3:sys:/dev:
     sync:*:4:100:sync:/bin:/bin/sync
     games:*:5:100:games:/usr/games:
     man:*:6:100:man:/var/catman:
     lp:*:7:7:lp:/var/spool/lpd:
     mail:*:8:8:mail:/var/spool/mail:
     news:*:9:9:news:/var/spool/news:
     uucp:*:10:50:uucp:/var/spool/uucp:
     nobody:*:65534:65534:noone at all,,,,:/dev/null:
     +miquels::::::
     +:*:::::/etc/NoShell
     [ All normal users AFTER this line! ]
     tester:*:299:10:Just a test account:/tmp:
     miquels:1234567890123:101:10:Miquel van Smoorenburg:/home/miquels:/bin/zsh

Thus the user "tester" will exist, but have a shell of /etc/NoShell. miquels will have normal access.

Alternatively, you could edit the /var/yp/Makefile file and set NIS to use another source password file. On large systems the NIS password and group files are usually stored in /etc/yp/. If you do this the normal tools to administrate the password file such as passwd, chfn, adduser will not work anymore and you need special homemade tools for this.

However, yppasswd, ypchsh and ypchfn will work of course.


10. Verifying the NIS/NYS Installation

If everything is fine (as it should be), you should be able to verify your installation with a few simple commands. Assuming, for example, your passwd file is being supplied by NIS, the command

    % ypcat passwd

should give you the contents of your NIS passwd file. The command

    % ypmatch userid passwd

(where userid is the login name of an arbitrary user) should give you the user's entry in the NIS passwd file. The "ypcat" and "ypmatch" programs should be included with your distribution of traditional NIS or NYS.

If a user cannot log in, run the following program on the client:
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>

int
main(int argc, char *argv[])
{
  struct passwd *pwd;

  if(argc != 2)
    {
      fprintf(stderr,"Usage: getwpnam username\n");
      exit(1);
    }

  pwd=getpwnam(argv[1]);

  if(pwd != NULL)
    {
      printf("name.....: [%s]\n",pwd->pw_name);
      printf("password.: [%s]\n",pwd->pw_passwd);
      printf("user id..: [%d]\n", pwd->pw_uid);
      printf("group id.: [%d]\n",pwd->pw_gid);
      printf("gecos....: [%s]\n",pwd->pw_gecos);
      printf("directory: [%s]\n",pwd->pw_dir);
      printf("shell....: [%s]\n",pwd->pw_shell);
    }
  else
    fprintf(stderr,"User \"%s\" not found!\n",argv[1]);

  exit(0);
}

Running this program with the username as parameter will print all the information the getpwnam function gives back for this user. This should show you which entry is incorrect. The most common problem is, that the password field is overwritten with a "*".

GNU C Library 2.1 (glibc 2.1) comes with a tool called getent. Use this program instead the above on such a system. You could try:
   getent passwd
or
   getent passwd login


11. Creating and Updating NIS maps

11.1. Creating new NIS maps

The initial NIS maps will be created by running

    % /usr/lib/yp/ypinit -m

This is done when setting up the NIS master server for the first time. For more information about this, read Section 9. If you wish to add new maps to your server or remove old one, you need to edit the /var/yp/Makefile and change the all: rule. Add or remove the name of the rule, which generates the map.

If you delete a map, you also have to remove the corresponding files.

After this change, you only need to run

    % make -C /var/yp

and the maps should be created.


11.3. Length of Map entries

The length of one entry is limited by the NIS protocol to 1024 characters. You can't just increase this value and recompile the system. Every system that uses NIS v2 expects key and data values to be no more than 1024 bytes in size; if you suddenly make YPMAXRECORD larger on your client and server, you will break interoperability with all other systems on your network that use NIS. To make it work right, you'd have to go to every vendor that supports NIS and get them to all make the change at the same time. Chances are you won't be able to do this.

With glibc 2.1 and newer this limit was removed from the glibc NIS implementation. So it is possible under Linux to use longer entries, but only if you have no other NIS clients or servers in your network.

To allow the creation of NIS maps with a longer entry, you need to add the --no-limit-check option to the makedbm call in /var/yp/Makefile.

The result should look like:

DBLOAD = $(YPBINDIR)/makedbm -c -m `$(YPBINDIR)/yphelper --hostname` --no-limit-check

WARNING: This breaks the NIS protocol and even if Linux supports it, not all Applictions running under Linux works with this change!

There is another way of solving this problem for /etc/group entries. This idea is from Ken Cameron:

1. Break the entry into more than one line and name each group
   slightly differnet.

2. keep the GID the same for all.

3. have the first entry with the right group name and the GID.
   I don't put any user names in this one.

What happens is that going by user name you pick up the GID when the code
reads it. Then going the other way it stops after the first match of GID
and takes that name. It's ugly but works!

12. Surviving a Reboot

Once you have NIS correctly configured on the server and client, you do need to be sure that the configuration will survive a reboot.

There are two separate issues to check: the existence of an init script and the correct storage of the NIS domain name.


13. Common Problems and Troubleshooting NIS

Here are some common problems reported by various users:

  1. The libraries for 4.5.19 are broken. NIS won't work with it.

  2. If you upgrade the libraries from 4.5.19 to 4.5.24 then the su command breaks. You need to get the su command from the slackware 1.2.0 distribution. Incidentally that's where you can get the updated libraries.

  3. When a NIS server goes down and comes up again ypbind starts complaining with messages like:
        yp_match: clnt_call:
        RPC: Unable to receive; errno = Connection refused
    and logins are refused for those who are registered in the NIS database. Try to login as root and kill ypbind and start it up again. An update to ypbind 3.3 or higher should also help.

  4. After upgrading the libc to a version greater then 5.4.20, the YP tools will not work any longer. You need yp-tools 1.2 or later for libc >= 5.4.21 and glibc 2.x. For earlier libc version you need yp-clients 2.2. yp-tools 2.x should work for all libraries.

  5. In libc 5.4.21 - 5.4.35 yp_maplist is broken, you need 5.4.36 or later, or some YP programs like ypwhich will segfault.

  6. libc 5 with traditional NIS doesn't support shadow passwords over NIS. You need libc5 + NYS or glibc 2.x.

  7. ypcat shadow doesn't show the shadow map. This is correct, the name of the shadow map is shadow.byname, not shadow.

  8. Solaris doesn't use always privileged ports. So don't use password mangling if you have a Solaris client.


14. Frequently Asked Questions

Most of your questions should be answered by now. If there are still questions unanswered you might want to post a message to

    comp.os.linux.networking