8273327
LDAP Support in DHCP
8273327
Brian Masney <masneyb@ntelos.net>
8273327
Last updated 3/23/2003
8273327
8273327
This document describes setting up the DHCP server to read it's configuration
8273327
from LDAP.  This work is based on the IETF document
8273327
draft-ietf-dhc-ldap-schema-01.txt included in the doc directory.  For the
8273327
latest version of this document, please see http://home.ntelos.net/~masneyb.
8273327
8273327
First question on most people's mind is "Why do I want to store my
8273327
configuration in LDAP?"  If you run a small DHCP server, and the configuration
8273327
on it rarely changes, then you won't need to store your configuration in LDAP.
8273327
But, if you have several DHCP servers, and you want an easy way to manage your
8273327
configuration, this can be a solution.
8273327
8273327
The first step will be to setup your LDAP server.  I am using OpenLDAP from
8273327
www.openldap.org.  Building and installing OpenLDAP is beyond the scope of
8273327
this document.  There is plenty of documentation out there about this.  Once
8273327
you have OpenLDAP installed, you will have to edit your slapd.conf file.  I
8273327
added the following 2 lines to my configuration file:
8273327
8273327
include         /etc/ldap/schema/dhcp.schema
8273327
index           dhcpHWAddress eq
8273327
index           dhcpClassData eq
8273327
8273327
The first line tells it to include the dhcp schema file.  You will find this
8273327
file under the contrib directory in this distribution.  You will need to copy
8273327
this file to where your other schema files are (maybe
8273327
/usr/local/openldap/etc/openldap/schema/).  The second line sets up an index
8273327
for the dhcpHWAddress parameter.  The third parameter is for reading subclasses
8273327
from LDAP every time a DHCP request comes in. Make sure you run the slapindex
8273327
command and restart slapd to have these changes to into effect.
8273327
8273327
Now that you have LDAP setup, you should be able to use gq
8273327
(http://biot.com/gq/) to verify that the dhcp schema file is loaded into LDAP.
8273327
Pull up gq, and click on the Schema tab.  Go under objectClasses, and you
8273327
should see at least the following object classes listed: dhcpClass, dhcpGroup,
8273327
dhcpHost, dhcpOptions, dhcpPool, dhcpServer, dhcpService, dhcpSharedNetwork,
8273327
dhcpSubClass, and dhcpSubnet.  If you do not see these, you need to check over
8273327
your LDAP configuration before you go any further.
8273327
8273327
You should now be ready to build DHCP.  If you would like to enable LDAP over
8273327
SSL, you will need to perform the following steps:
8273327
8273327
  * Edit the includes/site.h file and uncomment the USE_SSL line
8273327
    or specify "-DUSE_SSL" via CFLAGS.
8273327
  * Edit the dst/Makefile.dist file and remove md5_dgst.c and md5_dgst.o
8273327
    from the SRC= and OBJ= lines (around line 24)
8273327
  * Now run configure in the base source directory. If you chose to enable
8273327
    LDAP over SSL, you must append -lcrypto -lssl to the LIBS= line in the
8273327
    file work.os/server/Makefile (replace os with your operating system,
8273327
    linux-2.2 on my machine).  You should now be able to type make to build
8273327
    your DHCP server.
8273327
8273327
If you choose to not enable LDAP over SSL, then you only need to run configure
8273327
and make in the toplevel source directory.
8273327
8273327
Once you have DHCP installed, you will need to setup your initial plaintext
8273327
config file. In my /etc/dhcpd.conf file, I have:
8273327
8273327
ldap-server "localhost";
8273327
ldap-port 389;
8273327
ldap-username "cn=DHCP User, dc=ntelos, dc=net";
8273327
ldap-password "blah";
8273327
ldap-base-dn "dc=ntelos, dc=net";
8273327
ldap-method dynamic;
8273327
ldap-debug-file "/var/log/dhcp-ldap-startup.log";
8273327
8273327
If SSL has been enabled at compile time using the USE_SSL flag, the dhcp
8273327
server trys to use TLS if possible, but continues without TLS if not.
8273327
8273327
You can modify this behaviour using following option in /etc/dhcpd.conf:
8273327
8273327
ldap-ssl <off | ldaps | start_tls | on>
8273327
   off:       disables TLS/LDAPS.
8273327
   ldaps:     enables LDAPS -- don't forget to set ldap-port to 636.
8273327
   start_tls: enables TLS using START_TLS command
8273327
   on:        enables LDAPS if ldap-port is set to 636 or TLS in 
8273327
              other cases.
8273327
8273327
See also "man 5 ldap.conf" for description the following TLS related 
8273327
options:
8273327
   ldap-tls-reqcert, ldap-tls-ca-file, ldap-tls-ca-dir, ldap-tls-cert
8273327
   ldap-tls-key, ldap-tls-crlcheck, ldap-tls-ciphers, ldap-tls-randfile
8273327
8273327
All of these parameters should be self explanatory except for the ldap-method.
8273327
You can set this to static or dynamic.  If you set it to static, the
8273327
configuration is read once on startup, and LDAP isn't used anymore.  But, if
8273327
you set this to dynamic, the configuration is read once on startup, and the
8273327
hosts that are stored in LDAP are looked up every time a DHCP request comes
8273327
in.
8273327
8273327
When the optional statement ldap-debug-file is specified, on startup the DHCP
8273327
server will write out the configuration that it generated from LDAP.  If you
8273327
are getting errors about your LDAP configuration, this is a good place to
8273327
start looking.
8273327
8273327
The next step is to set up your LDAP tree. Here is an example config that will
8273327
give a 10.100.0.x address to machines that have a host entry in LDAP.
8273327
Otherwise, it will give a 10.200.0.x address to them.  (NOTE: replace
8273327
dc=ntelos, dc=net with your base dn). If you would like to convert your
8273327
existing dhcpd.conf file to LDIF format, there is a script
8273327
contrib/dhcpd-conf-to-ldap.pl that will convert it for you.  Type
8273327
dhcpd-conf-to-ldap.pl --help to see the usage information for this script.
8273327
8273327
# You must specify the server's host name in LDAP that you are going to run
8273327
# DHCP on and point it to which config tree you want to use.  Whenever DHCP
8273327
# first starts up, it will do a search for this entry to find out which
8273327
# config to use
8273327
dn: cn=brian.ntelos.net, dc=ntelos, dc=net
8273327
objectClass: top
8273327
objectClass: dhcpServer
8273327
cn: brian.ntelos.net
8273327
dhcpServiceDN: cn=DHCP Service Config, dc=ntelos, dc=net
8273327
8273327
# Here is the config tree that brian.ntelos.net points to.
8273327
dn: cn=DHCP Service Config, dc=ntelos, dc=net
8273327
cn: DHCP Service Config
8273327
objectClass: top
8273327
objectClass: dhcpService
8273327
dhcpPrimaryDN: dc=ntelos, dc=net
8273327
dhcpStatements: ddns-update-style none
8273327
dhcpStatements: default-lease-time 600
8273327
dhcpStatements: max-lease-time 7200
8273327
8273327
# Set up a shared network segment
8273327
dn: cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
8273327
cn: WV
8273327
objectClass: top
8273327
objectClass: dhcpSharedNetwork
8273327
8273327
# Set up a subnet declaration with a pool statement.  Also note that we have
8273327
# a dhcpOptions object with this entry
8273327
dn: cn=10.100.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
8273327
cn: 10.100.0.0
8273327
objectClass: top
8273327
objectClass: dhcpSubnet
8273327
objectClass: dhcpOptions
8273327
dhcpOption: domain-name-servers 10.100.0.2
8273327
dhcpOption: routers 10.100.0.1
8273327
dhcpOption: subnet-mask 255.255.255.0
8273327
dhcpOption: broadcast-address 10.100.0.255
8273327
dhcpNetMask: 24
8273327
8273327
# Set up a pool for this subnet.  Only known hosts will get these IPs
8273327
dn: cn=Known Pool, cn=10.100.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
8273327
cn: Known Pool
8273327
objectClass: top
8273327
objectClass: dhcpPool
8273327
dhcpRange: 10.100.0.3 10.100.0.254
8273327
dhcpPermitList: deny unknown-clients
8273327
8273327
# Set up another subnet declaration with a pool statement
8273327
dn: cn=10.200.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
8273327
cn: 10.200.0.0
8273327
objectClass: top
8273327
objectClass: dhcpSubnet
8273327
objectClass: dhcpOptions
8273327
dhcpOption: domain-name-servers 10.200.0.2
8273327
dhcpOption: routers 10.200.0.1
8273327
dhcpOption: subnet-mask 255.255.255.0
8273327
dhcpOption: broadcast-address 10.200.0.255
8273327
dhcpNetMask: 24
8273327
8273327
# Set up a pool for this subnet. Only unknown hosts will get these IPs
8273327
dn: cn=Known Pool, cn=10.200.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
8273327
cn: Known Pool
8273327
objectClass: top
8273327
objectClass: dhcpPool
8273327
dhcpRange: 10.200.0.3 10.200.0.254
8273327
dhcpPermitList: deny known clients
8273327
8273327
# Set aside a group for all of our known MAC addresses
8273327
dn: cn=Customers, cn=DHCP Service Config, dc=ntelos, dc=net
8273327
objectClass: top
8273327
objectClass: dhcpGroup
8273327
cn: Customers
8273327
8273327
# Host entry for my laptop
8273327
dn: cn=brianlaptop, cn=Customers, cn=DHCP Service Config, dc=ntelos, dc=net
8273327
objectClass: top
8273327
objectClass: dhcpHost
8273327
cn: brianlaptop
8273327
dhcpHWAddress: ethernet 00:00:00:00:00:00
8273327
8273327
You can use the command slapadd to load all of these entries into your LDAP 
8273327
server. After you load this, you should be able to start up DHCP. If you run
8273327
into problems reading the configuration, try running dhcpd with the -d flag. 
8273327
If you still have problems, edit the site.conf file in the DHCP source and
8273327
add the line: COPTS= -DDEBUG_LDAP and recompile DHCP. (make sure you run make 
8273327
clean and rerun configure before you rebuild).
8273327