Official website for Linux User & Developer
FOLLOW US ON:
Dec
15

Building a network of Raspberry Pis

by Liam Fraser

Learn how to set up a network of Raspberry Pis with centralised authentication and file storage

In this tutorial, we’ll learn to set up a Network Information Services server on a Raspberry Pi that centralises some of the configuration of Linux systems. This includes user accounts. This means that we can set up users on the Raspberry Pi server and have them available on each client Raspberry Pi. This arrangement would be useful in a classroom situation where there were a number of Raspberry Pis shared between classes. Each child would have a username and password, and they would have access to all of their files from any Raspberry Pi once they have logged in. One big advantage of this is that each user’s files can be backed up from a single place. We’ll also be giving some examples of software that could be used in a classroom on the Raspberry Pi.

We’ll be using the latest Raspbian image as the operating system for both our Raspberry Pi server and Raspberry Pi clients, so we’ll need to start by
writing that to two SD cards. Note that we’ll be making a master SD card for the clients which can then be written to the rest of the SD cards, so only write the image to two of them.

The instructions for flashing an image to an SD card can be found on our Set-up Guide. You will only need to go up to the step where you write the image to the SD card. Note that you will have to adapt the instructions slightly for using the latest Raspbian image rather than the Debian one. The image that we used was 2012-09-18- wheezy-raspbian.zip.

We are going to assume that you are plugging the Raspberry Pis into an existing network with DHCP, a protocol for handing out network settings to devices that connect to said network. This way, they can get access to the internet for installing packages and other useful things such as teaching resources.

Resources

At least 2 Raspberry Pis (with appropriate perpiherals)
SD card
Computer
Network switch
Ethernet cable
Storage device

Step by Step

Network
Initial Configuration

Step 01

Initial configuration of the server
Raspberry Pi

Connect a keyboard, mouse, Ethernet cable, monitor and, lastly, power to your server Raspberry Pi. Raspbian will boot and a configuration menu will be displayed. You need to select the option to expand_rootfs to make sure that you’re using the entire space of the SD card. You should definitely change the password for the pi user so that no one can log into your server with the standard credentials of Username: pi and Password: raspberry. Then change the memory split to 240MiB for ARM and 16MiB for the VideoCore. Finally, enable SSH, then select ‘Finish’. Select ‘Yes’ to reboot now.

Step 02

Fire up your Linux computer

Now that we have enabled SSH on the server Raspberry Pi, we can configure it remotely using SSH as long as your Linux computer is on the same network (if not, connect it now). We might as well make sure that SSH works now for when a monitor is no longer needed. During the boot process of Raspbian, a message will be displayed with the current IP address of the Pi. Open up a terminal on your Linux computer and type ‘ssh pi@ [your Pi’s IP address]’. Type ‘yes’ when asked if you want to connect and then enter the new password
that you set. You are now logged into your server Pi.

Step 03

Setting up a static IP address

We highly recommend assigning a static IP to your server Raspberry Pi because you, and more importantly the client Raspberry Pis, will always know where to find it on the network. We’ll need to find out a couple of things about your current network setup before setting a static IP. You can use the commands ‘ifconfig eth0’ and ‘ip route show’ to do this. We’ve included the important output from our commands below so that you can see what to do with each value. Now that we have found out things about your network, such as your current IP address, the network mask and so on, we can set up a static IP address. Use the command:

sudo nano /etc/network/interfaces

to edit the networking configuration file. Use the arrows to navigate and start by deleting the line ‘iface eth0 inet dhcp’. Then replace it with lines similar to the following:

iface eth0 inet static
address 172.17.173.249
netmask 255.255.255.0
gateway 172.17.173.1

Make sure that the IP address you assign to your Raspberry Pi server isn’t taken. You’ll want to discuss this with your network administrator if you have one, but it’s usually safe to assume that the address the device had already won’t be taken. You’ll also want to note down that IP address for future usage.

Save the changes in nano using the key combination Ctrl+O followed by Enter. You can exit nano using Ctrl+X.

You might notice that we haven’t done anything about the DNS server. DNS is used to resolve hostnames such as google.co.uk to an IP address. The IP address of the DNS server is stored in /etc/resolv.conf and will not change value after changing to a static IP address.

pi@raspberrypi ~ $ ifconfig eth0
eth0 Link encap:Ethernet
HWaddr xx:xx:xx:xx:xx:xx
          inet addr:172.17.173.249
Bcast:172.17.173.255
Mask:255.255.255.0
pi@raspberrypi ~ $ ip route show
default via 172.17.173.1 dev eth0
172.17.173.0/24 dev eth0
proto kernel  scope link  src
172.17.173.249

Step 04

Restart the server Pi

Restart the server Pi so that the networking changes we just made can take place. Log back in using SSH and the new IP address that you chose.

Step 05

Installing the required packages for an NFS server

NFS stands for Network File System, and is what we’ll use to share each user’s home directory. Run the command:

sudo apt-get update

…to update the package lists on the device, followed by:

sudo apt-get install nfs-kernel- server nfs-common rpcbind

…to install the packages required for an NFS server. You’ll probably get a message like ‘[warn] Not starting NFS kernel daemon: no exports…. (warning)’. This is just telling us that the NFS server hasn’t started because we haven’t set it up to share (export) any directories yet.

Step 06

Exporting directories

Add the line:

/home *(rw,sync)

to the end of /etc/exports using nano. The line means share the /home directory with everyone, permitting read and write access. Although
this sounds insecure, other users will only get read access to directories that aren’t their own and therefore won’t be able to delete or change files. NFS requires rpcbind, so you need to start that before NFS. Rpcbind doesn’t start on boot by default on Raspbian, but we want it to. You can do this using the command ‘sudo update- rc.d rpcbind enable’. You can start them both immediately using the following commands:

sudo /etc/init.d/rpcbind start
sudo /etc/init.d/nfs-kernel-server
start

Step 07

Installing NIS

NIS stands for Network Information Services and used to be called Yellow Pages, or yp for short. Many of the services and directories still have ‘yp’ in the name. Use the command ‘sudo apt-get install nis’ to install Network Information Services. Accept any extra packages that may be required. You will now be taken to the package configuration screen for NIS. It will start by asking you to enter an NIS domain. This can be anything you like, but we’re calling ours raspberrypi. Once you have set that, NIS will continue to install and then the NIS services will attempt to start. This will take a few minutes and fail, so don’t worry when that happens. We need to do more configuration before it will work.

Step 08

Configuring NIS

We need to do a few things before our NIS server will work. The first thing we need to do is open up /etc/default/nis with nano as we do in the usual way. Make sure you prefix the nano command with sudo because we need root privileges to edit each of these files. You need to change the line:

NISSERVER=false

to

NISSERVER=master

and also change the line

NISCLIENT=true

to

NISCLIENT=false

Save the changes and then exit nano. We then need to edit:

/var/yp/Makefile

and change the line

ALL = passwd group hosts rpc services netid protocols netgrp

to

ALL = passwd shadow group hosts rpc services netid protocols netgrp

The password file on Linux contains a list of users and various information about them such as their home directory and the User & Group IDs. We need to add the shadow file to the list because that file stores the password hashes for each user. We also need to change the line MINGID=1000 to MINGID=0
because we’ll be adding our NIS users to system groups such as audio so that they can play sound. The next step is to change the server’s hostname by editing the /etc/hostname file. We’re going to change our hostname from raspberrypi to nismaster. We then need to change /etc/hosts to complete the hostname change, as well as add an extra line. We need to do this because servers running NIS are added by name rather than their IP address. You’ll see this shortly. Plus, we should be able to differentiate the NIS server from all of the other Raspberry Pis anyway. Change the line 127.0.1.1 raspberrypi to 127.0.1.1 [your new hostname]

You’ll also need to add a new line for the IP address of the NIS server in the form:

[IP address] [hostname].[NIS domain] [hostname]
Raspberry Pi Network
Configure NIS

Step 09

Initialising the NIS master database

Before anything else, restart the Pi using sudo init 6 to let the host name change take place. Reconnect once the Pi has booted backup. Run the command:

sudo /usr/lib/yp/ypinit -m

and then press Ctrl + D followed by Enter. We can now start the NIS server using the command:

sudo /etc/init.d/nis start

Pages: 1 2
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.
    • Andy

      Nice Tutorial,

      In step 14 where you say “You also need to edit the /etc/nsswitch.conf file to look like ours.” Where is yours for reference and what does it look like?

      I have followed this every step but can’t get the client to log on as the user from the nismaster.

      Any help would be appreciated.

      Thanks

    • John Winters

      I was very pleased to find this tutorial because I’ve been struggling to set up exactly this kind of configuration with RPs as clients (bigger computer running Debian Wheezy as the server).

      One thing though – the instructions look OK, but did you actually test whether they were complete and produced a working result? From my experience:

      1) The step of editing SHADOW into the file list is unnecessary – if you look just a smidge further down the Makefile you’ll see it gets included automatically if /etc/shadow exists.

      2) You need to enable rpcbind in /etc/rc2.d on the client or it will fail to bind with the server at boot time.

      3) As the previous commenter said, having done all the steps you list, login still doesn’t actually work. You can do a “ypcat passwd.byname” on the client (and indeed a “ypcat shadow.byname” if you’re root) so clearly the two boxes are communicating successfully, but you can’t log in using NIS credentials.

      A complete set of instructions would have been useful. Me – I’ll keep hunting for the missing step.

      John

    • John Winters

      Further item:

      4) You seem to have missed out the step of editing /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow on the client. Unless NIS configuration has changed since I last did it, the client won’t work without that.

      Even with that done though, things still don’t work.

      John

    • John Winters

      Correction to my previous comment:

      Step 4 – editing /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow on the client is indeed the missing step which will make things work. Mine wasn’t working because I messed up the editing of /etc/shadow and put only 7 colons instead of 8. Once that step is done correctly, the client will work and let you log on.

      See /usr/share/doc/nis/nis.debian.howto.gz for full details of the required edits.

    • Andy

      Thanks for the Heads up John, going to give it another go. I searched and searched but hadn’t come up with a solution.

      Cheers