Raspberry Pi Lab Setup

Table of Contents

Lab Setup

This is a short guide on how to set up a small test lab using a handful of Raspberry Pi machines.

The plan includes the following - the checked items show my progress so far:

  • [X] firewall/gateway/DNS/DHCP machine
  • [ ] a DEB package cache/proxy
  • [ ] syslog server
  • [ ] web server
  • [ ] database server
  • [ ] source-code version control system server
  • [ ] systems-management/automation server

Installing the DNS/DHCP package on the gateway/firewall may seem lazy - and probably is - but it eases the initial work allows us to only ever connect the the monitor and keyboard to the gateway machine.

The setup will connect to my wireless network using a WiFi USB unit on the gateway machine connected to the other machines via ethernet. The lab network will be configured as 192.168.111.0/24.

Note: configuration changes will be done using Perl one-liners - doing inline changes using regex substitution.

Prerequisites

Sadly there is no network boot functionality available when working with Raspberry Pi, so the initial setup of the RPi machines has been done manually - with the addition of enabling sshd.

The setup requires:

  • a handful of Raspberry Pi machines.
  • a SD-card with Raspian for each RPi.
  • a USB cable per RPI (connectors: micro-B-to-type-A, e.g. normal phone-charging cable)
  • an cat-5 cable per RPi.
  • a network switch (to connect the RPis).
  • a USB hub (so you don't need power cord for each individual RPi).
  • a USB Wifi card supported by Raspberry Pi/Raspian.

Note: functionality resembling network boot can be acquired if you create a custom image that supports this - although it will still be booting from the SD-card and then polling the network for further information.

Software

Utility Packages

  • APT front-end

    I prefer aptitude over apt-get/apt-query/etc - probably because I use 'aptitude search' a lot.

  • Terminal Multiplexer

    Using a terminal multiplexer on the gateway machine makes it easy to move from one machine to another. Just open a new window or pane and connect to the target host - easily moving back and forth between the hosts.

DHCP/DNS : dnsmasq

Installing (and configuring) the dnsmasq package will make the gateway act as DHCP and DNS server.

The official website notes that "Dnsmasq provides network infrastructure for small networks: DNS, DHCP, router advertisement and network boot." The "small network" part here seems to mean "multiple thousand hosts" if you look at some of the questions on the dnsmasq mailing list.

Gateway

Wireless Network

Plug in the wifi USB unit and make sure the unit is discovered by the kernel. There should be some lines referring to the USB unit at the end of the dmesg output (if you un-plug it and re-connect it).

dmesg

You need to edit the WPA_Supplicant configuration file.

sudo nano -w /etc/wpa_supplicant/wpa_supplicant.conf

Add the following at the top of the file.

network={
        ssid="YOUR_WLAN_ESSID"
        pki="YOUR_WLAN_PASSPHRASE"
}

And restart the wlan0 interface

sudo ifdown wlan0
sudo ifup wlan0

Wait 10-15 seconds to allow the wireless authentication and configuration to take place. Then list the wlan0 properties to see if it acquired an IP address from the router.

ifconfig wlan0

Wired Network

Do not edit the interfaces file to set up the eth0 interface!!

In stead edit the /etc/dhcpcd.conf file so that the DHCP Client Daemon will take care of business (this is the official "new" way of setting a static IP on RPi).

sudo nano -w /etc/dhcpcd.conf

Add the following to at the bottom of the file.

interface eth0
     static ip_address=192.168.111.20/24

The bring the eth0 interface down and up again.

sudo ifconfig eth0 down;
sleep 5;
sudo ifconfig eth0 up;

Enable forwarding of traffic from RPi Lab network on eth0 to wlan0

sudo su -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'

… or edit /etc/sysctl.conf

net.ipv4.ip_forward=1

Reload sysctl settings

sudo sysctl --system

Tell iptables to do network-address-translation and forward packets between eth0 and wlan0.

# sudo iptables -I FORWARD 1 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
/sbin/iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

Packages

Installing dnsmasq along with my preferred APT front-end and a terminal multiplexer.

sudo apt-get install dnsmasq aptitude tmux

Update all installed packages.

sudo aptitude update && sudo aptitude safe-upgrade

dnsmasq

Configure dnmasq to listen only on the eth0 interface (as I've already got a DHCP and DNS server on my (W)LAN).

perl -i -lpe 's/^#interface=.*/interface=eth0/' /etc/dnsmasq.conf

Enable the DHCP functionality by setting the range of IP addresses dnsmasq will offer to DHCP clients. I'm setting it to use one-hundred IPs in the 192.168.111.0-network (from .50 to .150).

perl -i -lpe 's/^#dhcp-range=.*/dhcp-range=192.168.111.50,192.168.111.150,12h/' /etc/dnsmasq.conf

Restart the dnsmasq service.

sudo service dnsmasq restart

Author: Rói á Torkilsheyggi

Created: 2016-07-27 Wed 20:40

Emacs 24.5.1 (Org mode 8.2.10)

Validate