The full form of NIS is Network Information Server. NIS server stores all the user information in a database. NIS client can use the NIS server to authenticate these users and use it locally. Basically, NIS is used for centralizing authentication in a network. NIS is an alternative to Lightweight Directory Access Protocol or LDAP in short.  In this article, I am going to show you how to install and configure NIS server on Ubuntu 18.04 LTS server. So, let’s get started.

Network Topology:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Here, we have 2 machines with Ubuntu Server 18.04 LTS operating system installed.

In this article,

NIS Server:

Hostname = nis-server.linuxhint.local

IP Address = 192.168.20.167/24

NIS Client:

Hostname = client

IP Address = 192.168.20.168/24

Things You Must Know:

The NIS server nis-server.linuxhint.local must have an static IP address configured. In this article, it’s configured with the static IP 192.168.20.167client machine must be on the same network as the nis-server.linuxhint.local server.  The hostname must be a Fully Qualified Domain Name (FQDN) and configured correctly in the NIS server. Here, the NIS server has the hostname nis-server.linuxhint.local and the domain name linuxhint.local

You may use DNS server to resolve hostname and domain name. You can also use the /etc/hosts file. In this article, I will be using the /etc/hosts file for DNS resolution. The client machine must also be able to resolve the NIS server hostname and domain name. You can also use either a DNS server or /etc/hosts file for DNS resolution in the client machine.

Setting Static IP in NIS Server:

First, find the network interface name with the following command:

Here, the network interface name is ens33 in my case. It may be different for you. Make sure to replace it with yours from now on.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, edit the /etc/netplan/50-cloud-init.yaml file with the following command:

$ sudo nano /etc/netplan/50-cloud-init.yaml

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, add the following lines to the file. Make sure to adjust the IP addresses depending your networking configuration. Once you’re done, save the file.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, apply the network configuration with the following command:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Configuring DNS in NIS Server:

Now, open the /etc/hosts file of the NIS server as follows:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, add the following line to the /etc/hosts file and save the file.

192.168.20.167 nis-server.linuxhint.local nis-server linuxhint.local

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, set a FQDN hostname nis-server.linuxhint.local to the NIS server with the following command:

$ sudo hostnamectl set-hostname nis-server.linuxhint.local

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, reboot the NIS server as follows:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Once the NIS server starts, the hostname should be set to nis-server.linuxhint.local.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Installing NIS Server:

Now, on the NIS server machine, update the APT package repository cache with the following command:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, install NIS server package with the following command:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

To confirm the installation, press Y and then press .

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, type in your domain name (linuxhint.local in my case), select and press .

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

NIS server should be installed.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Configuring NIS Server:

Now, open the configuration file /etc/default/nis with the following command:

$ sudo nano /etc/default/nis

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

You have to change the 2 lines as marked in the screenshot below.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Set NISSERVER to master and NISCLIENT to false as shown in the screenshot below. Then, save the file.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, open the /etc/ypserv.securenets file as follows:

$ sudo nano /etc/ypserv.securenets

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Add a hash before the marked line to comment it out.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Then, add your own network’s netmask and network address in the following format:

netmask    network-address

Then, save the file.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, initialize the NIS server database with the following command:

$ sudo /usr/lib/yp/ypinit -m

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Your FQDN hostname should be listed here. Now, press D.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

To confirm, press Y and then press .

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

NIS server database should be initialized.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, restart NIS service with the following command:

$ sudo systemctl restart rpcbind nis

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Adding User to NIS Server:

Now, you can add new users to the NIS server.

To add a new user user1 (let’s say), run the following command:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, type in a password for the user user1 and press .

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Retype the password and press .

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, type in some user information.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Once you’re done adding all the user information, press Y and then press to confirm.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

The user user1 should be created.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

The same way, add another user user2.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

The same way, add another user user3.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Every time you make new users or change user information i.e. name, home directory, password etc., you must update the NIS user database.

To do that, navigate to /var/yp directory first.

Now, run the following command from the /var/yp directory to update the NIS user database.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Configuring NIS Client:

In the NIS client, first add the hostname and domain name of the NIS server to the /etc/hosts file.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Add the following line to the /etc/hosts file and save the file.

192.168.20.167 nis-server.linuxhint.local nis-server linuxhint.local

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, update the APT package repository cache of the NIS client machine.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, install NIS package in the NIS client machine as follows:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

To confirm the installation, press Y and then press .

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Type in the NIS server’s domain name (linuxhint.local in this case) and press .

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

NIS package should be installed.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, open /etc/yp.conf file as follows:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, add the following line at the end of the /etc/yp.conf file and save it.

domain linuxhint.local server nis-server.linuxhint.local

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, open the /etc/nsswitch.conf file as follows:

$ sudo nano /etc/nsswitch.conf

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

You have to modify the marked lines.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Add nis at the end of each line as marked in the screenshot below. Once you’re done, save the file.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

You also have to mount the home directories of the NIS users to your NIS client. You can use iSCSI, NFS, CIFS (Samba) to do that. But it is out of the scope of this article. So, I will keep the NIS users home directory in the NIS client’s local filesystem.

When you login as your NIS users, they will automatically create their own home directories in the /home directory of the NIS client machine. To allow them that privilege, you have to configure PAM of the NIS client machine.

To configure PAM, open /etc/pam.d/common-session configuration file as follows:

$ sudo nano /etc/pam.d/common-session

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, add the following line at the end of the file and save the file.

session optional pam_mkhomedir.so skel=/etc/skel umask=007

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Now, reboot the NIS client machine as follows:

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Testing NIS Server:

Once the NIS client machine boots, you should be able to login as the users that you’ve created earlier in the NIS server machine.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

As you can see, I’ve successfully logged in as user1 in the NIS client machine.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

The home directory of user1, /home/user1 is automatically created as well.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

By default, the NIS users will be in their own home directory as you can see in the screenshot below.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Once NIS client is configured, you can see information about all the NIS users with the following command:

All the users you’ve created in the NIS server machine should be listed here as you can see in the screenshot below.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

As you can see, I can also login as user2 and user3 from the NIS client machine. NIS is working correctly.

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

So, that’s how you install and configure NIS server on Ubuntu Server 18.04 LTS. Thanks for reading this article.

About the author

Installing NIS server on Ubuntu 18.04 LTS Networking ubuntu

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.