Building a network of Raspberry Pis
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.
At least 2 Raspberry Pis (with appropriate perpiherals)
Step by Step
Initial configuration of the server
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.
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.
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
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.
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.
Add the line:
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
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.
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:
and also change the line
Save the changes and then exit nano. We then need to edit:
and change the line
ALL = passwd group hosts rpc services netid protocols netgrp
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]
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