Next Previous Contents

4. Configuration

DHCP is very tricky, and failover is very new. It took me a few days to figure out the syntax for the pool and failover declerations.

4.1 Primary DHCP Server

dhcpd.conf

This is system specific for the failover declaration. When I say " system specific" I mean specific to the primary dhcp server as in IP, port, and a few other options. In this case, some options that are only for the primary dhcp server.

Put the following in your dhcpd.conf on the primary dhcp server:

ddns-update-style none;
one-lease-per-client true;
option domain-name "mydomain.com";
option domain-name-servers 10.254.0.3, 10.254.0.4;
option subnet-mask 255.255.0.0;
default-lease-time 300; max-lease-time 300;
authoritative;
failover peer "dhcp" { 
  primary; 
  address 10.254.0.9;
  port 519; 
  peer address 10.254.0.8;
  peer port 520; 
  max-response-delay 60;
  max-unacked-updates 10;
  mclt 600;
  split 128;
  load balance max seconds 3;
}
include "/etc/dhcpd.master";

4.2 Secondary DHCP Server

dhcpd.conf

You will notice that there are a few options missing from the failover declaration. This is becuase the secondary dhcp server doesn't need those options.

Now put the following in your dhcpd.conf on your secondary dhcp server:

ddns-update-style none;
one-lease-per-client true;
option domain-name "mydomain.com";
option domain-name-servers 10.254.0.3, 10.254.0.4;
option subnet-mask 255.255.0.0;
default-lease-time 300; max-lease-time 300;
authoritative;
failover peer "dhcp" { 
  secondary;
  address 10.254.0.8;
  port 520;
  peer address 10.254.0.9;
  peer port 519;
  max-response-delay 60;
  max-unacked-updates 10;
}
include "/etc/dhcpd.master";

4.3 Master DHCP Configuration file

dhcpd.master

This should be on both servers. This file contains all of the subnet declarations you define.

Put the following in /etc/dhcpd.master:

subnet 10.254.0.0 netmask 255.255.0.0 { 
  pool { 
    failover peer "dhcp";
    range 10.254.0.10 10.254.255.254;
    deny dynamic bootp clients;
  } 
  option routers 10.254.0.1;
}

4.4 Startup script

Put this in /etc/init.d/dhcp:

#!/bin/bash
DAEMON=/usr/sbin/dhcpd
CONF=/etc/dhcpd.conf
NAME=DHCP
PIDFILE=/var/run/dhcpd.pid
IFDEV=eth0
DHCPOPTS="-q $IFDEV"

[ -x $DAEMON ] || exit 0
[ -f $CONF ] || exit 0

# Safety check
if [ ! -f /var/state/dhcp/dhcpd.leases ]; then
  touch /var/state/dhcp/dhcpd.leases fi
fi
case "$1" in 
  start)
    echo -n "Starting $NAME Server: "
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DHCPOPTS
    echo "done"
    ;;
  stop)
    echo -n "Stopping $NAME Server: "
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON -- -$DHCPOPTS
    echo "done"
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
  *)
    echo "usage: $0 start|stop|restart"
    exit 1
    ;;
esac


Next Previous Contents