Set up DHCP server

Date: July 6th 2016
Last updated: July 6th 2016

The end goal of setting up a DHCP server is to run hadoop. This entry is just a recap of the steps I followed from various blogs and posts.

Ultimately, I want a primary access point (head node) from the outside world (mostly locally via my router using ssh), while the remaining compute nodes (three RPi's) are accessible on a subnet served up by the head node.

Mostly I followed this article to setup the DHCP server: http://makezine.com/projects/build-a-compact-4-node-raspberry-pi-cluster/. However, as a hardware/network beginner I had to do a little extra research at several steps to complete the setup.

what I'm using:

  1. Raspberry Pis
    1. 1 x Raspberry Pi model B+ (compute node)
    2. 1 x Raspberry Pi 2 (compute node)
    3. 2 x Raspberry Pi 3's (one compute node, one master)
  2. 4 x 8 GB micro SD cards
  3. Anker 6 port 60 watt powered hub (supplies 2.5 amp per port)
  4. 4 x 20cm USB to micro usb android cables (rated at 2 amp)
  5. DLink 5 port network switch
  6. 4 x network cables (0.5m)
  7. Comsol USB to ethernet adaptor
  8. 16 GB flash drive
  9. some other housing accessories (nylon spacers etc)

Assumed start point

  1. All Pi's have Raspbian installed
  2. File system has been expanded
  3. Password changed on all Pi's
  4. Host names updated to (i.e. sudo nano /etc/hosts)...

    1. rpi1 (head; RPi model 3),
    2. rpi2 (RPi model 3),
    3. rpi3 (RPi model 2),
    4. rpi4 (RPi model B+)
  5. All Pi's are plugged into the router (along with the external ethernet plugged into the network switch) and are visible in the routers DHCP client list.

Make sure you can access each RPi from another local machine

# from external laptop, assuming rpi1 is available on 192.168.1.108
ssh -vv [email protected]
# enter password
pi@rpi1$ 
# trial all RPi's

Next, I need to create a subnet with only one connection to the head node. This is where the USB to ethernet adaptor will be used. But not yet. For the following steps, leave the external ethernet connection plugged into the ethernet switch along side the connections for each Raspbserry Pi. I am not bothering to create a passwordless system yet (using the pi profile) because I am going to generate a user group and user profile for the Hadoop system. This will have a passwordless system. But more on that later.

The following steps are from "Build a Compact 4 Node Raspberry Pi Cluster" article

Edit /etc/network/interfaces on the head node

auto lo
iface lo inet loopback

auto eth1
allow-hotplug eth1
iface eth1 inet dhcp

auto eth0
allow-hotplug eth0
iface eth0 inet static
  address 192.168.50.1
  netmask 255.255.255.0
  network 192.168.50.0
  broadcast 192.168.50.255

Install DHCP server on head node

sudo apt-get install isc-dhcp-server

Edit /etc/dhcp/dhcpd.conf
Note that the first few lines are already in dhcp.conf. Scroll down and uncomment these lines. Also the things to update in this file include the host names and the MAC address for each RPi. Remove the greater than and less than signs surrounding ENTER MAC ADDRESS HERE as well. You can access the MAC address on each RPi using ifconfig at the terminal, or, you can log into your router and view the DHCP clients list (assuming they are all switched on of course). A final thing to note is that this group is identified by the name "cluster" which is used in /etc/hosts next.

ddns-update-style none;
authoritative;
log-facility local7;

# No service will be given on this subnet
subnet 192.168.1.0 netmask 255.255.255.0 {
}

# The internal cluster network
group {
   option broadcast-address 192.168.50.255;
   option routers 192.168.50.1;
   default-lease-time 600;
   max-lease-time 7200;
   option domain-name "cluster";
   option domain-name-servers 8.8.8.8, 8.8.4.4;
   subnet 192.168.50.0 netmask 255.255.255.0 {
      range 192.168.50.14 192.168.50.250;

      host rpi1 {
         hardware ethernet <ENTER MAC ADDRESS HERE>;
         fixed-address 192.168.50.1;
      }
      host rpi2 {
         hardware ethernet <ENTER MAC ADDRESS HERE>;
         fixed-address 192.168.50.11;
      }
      host rpi3 {
         hardware ethernet <ENTER MAC ADDRESS HERE>;
         fixed-address 192.168.50.12;
      }
      host rpi4 {
         hardware ethernet <ENTER MAC ADDRESS HERE>;
         fixed-address 192.168.50.13;
      }
   }
}

Edit /etc/default/isc-dhcp-server

DHCPD_CONF=/etc/dhcp/dhcpd.conf
DHCPD_PID=/var/run/dhcpd.pid
INTERFACES="eth0"

ON ALL NODES: edit /etc/hosts
It is expected that you can still access the RPi's via the IP address assigned by the router. Update each file with the following... I just copied and pasted over what ever else was in there. Note the use of "cluster" group generated in the DHCP file above.

127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.1.1 rpi1 rpi1.local rpi1.lan rpi1.cluster

192.168.50.1    rpi1 rpi1.local rpi1.lan rpi1.cluster
192.168.50.11   rpi1 rpi2.local rpi2.lan rpi2.cluster
192.168.50.12   rpi3 rpi3.local rpi3.lan rpi3.cluster
192.168.50.13   rpi4 rpi4.local rpi4.lan rpi4.cluster

Update hardware
Unplug the external ethernet cable from the switch and plug into the USB to ethernet adaptor on the head node. This frees up one port on the network switch. Reboot all RPi's - I just pulled the plug on the USB hub.

Things to expect: 1) the head node will get a new IP address (or probably the old one as in my case), 2) the compute nodes will have a permanent address (given in /etc/hosts) that is only accessible from the head node, 3) you wont be able to connect to the internet from each compute node. The next step will solve the third expectation so that I can install Hadoop on each Raspberry Pi.

Allow port forwarding

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

# edit /etc/sysctl.conf
# uncomment inside file
net.ipv4.ip_forward=1

# update IP tables (from command line)
sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
sudo iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

# add to the bottom of /etc/network/interfaces
up iptables-restore < /etc/iptables.ipv4.nat

results matching ""

    No results matching ""