1 LDAP Support in DHCP
2 Original Author: Brian Masney <masneyb (a] gftp.org>
3 Current Maintainer: David Cantrell <dcantrell (a] redhat.com>
4 Last updated 07-Jul-2009
5
6 This document describes setting up the DHCP server to read it's configuration
7 from LDAP. This work is based on the IETF document
8 draft-ietf-dhc-ldap-schema-01.txt included in the doc directory. For the
9 latest version of this document, please see
10 http://dcantrel.fedorapeople.org/dhcp/ldap-patch/
11
12 First question on most people's mind is "Why do I want to store my
13 configuration in LDAP?" If you run a small DHCP server, and the configuration
14 on it rarely changes, then you won't need to store your configuration in LDAP.
15 But, if you have several DHCP servers, and you want an easy way to manage your
16 configuration, this can be a solution.
17
18 The first step will be to setup your LDAP server. I am using OpenLDAP from
19 www.openldap.org. Building and installing OpenLDAP is beyond the scope of
20 this document. There is plenty of documentation out there about this. Once
21 you have OpenLDAP installed, you will have to edit your slapd.conf file. I
22 added the following 2 lines to my configuration file:
23
24 include /etc/ldap/schema/dhcp.schema
25 index dhcpHWAddress eq
26 index dhcpClassData eq
27
28 The first line tells it to include the dhcp schema file. You will find this
29 file under the contrib directory in this distribution. You will need to copy
30 this file to where your other schema files are (maybe /etc/openldap/schema/).
31 The second line sets up an index for the dhcpHWAddress parameter. The third
32 parameter is for reading subclasses from LDAP every time a DHCP request comes
33 in. Make sure you run the slapindex command and restart slapd to have these
34 changes to into effect.
35
36 Now that you have LDAP setup, you should be able to use gq
37 (http://biot.com/gq/) to verify that the dhcp schema file is loaded into LDAP.
38 Pull up gq, and click on the Schema tab. Go under objectClasses, and you
39 should see at least the following object classes listed: dhcpClass, dhcpGroup,
40 dhcpHost, dhcpOptions, dhcpPool, dhcpServer, dhcpService, dhcpSharedNetwork,
41 dhcpSubClass, and dhcpSubnet. If you do not see these, you need to check over
42 your LDAP configuration before you go any further.
43
44 You should now be ready to build DHCP. If you would like to enable LDAP in
45 dhcpd, you will need to perform the following steps:
46
47 * Apply the patch here to the unpacked ISC dhcp source tree.
48 * Regenerate the configure script (requires GNU autoconf and automake):
49 aclocal
50 libtoolize --copy --force
51 autoconf
52 autoheader
53 automake --foreign --add-missing --copy
54 * Run ./configure with the '--with-ldap' argument to enable OpenLDAP.
55 If you want LDAP over SSL, also use the '--with-ldapcrypto' argument.
56 * Run 'make' to build ISC dhcp.
57
58 Once you have DHCP installed, you will need to setup your initial plaintext
59 config file. In my /etc/dhcpd.conf file, I have:
60
61 ldap-server "localhost";
62 ldap-port 389;
63 ldap-username "cn=DHCP User, dc=ntelos, dc=net";
64 ldap-password "blah";
65 ldap-base-dn "dc=ntelos, dc=net";
66 ldap-method dynamic;
67 ldap-debug-file "/var/log/dhcp-ldap-startup.log";
68
69 If SSL has been enabled at compile time, the dhcp server trys to use TLS if
70 possible, but continues without TLS if not.
71
72 You can modify this behaviour using following option in /etc/dhcp/dhcpd.conf:
73
74 ldap-ssl <off | ldaps | start_tls | on>
75 off: disables TLS/LDAPS.
76 ldaps: enables LDAPS -- don't forget to set ldap-port to 636.
77 start_tls: enables TLS using START_TLS command
78 on: enables LDAPS if ldap-port is set to 636 or TLS in
79 other cases.
80
81 See also "man 5 ldap.conf" for description the following TLS related
82 options:
83 ldap-tls-reqcert, ldap-tls-ca-file, ldap-tls-ca-dir, ldap-tls-cert
84 ldap-tls-key, ldap-tls-crlcheck, ldap-tls-ciphers, ldap-tls-randfile
85
86 The ldap-init-retry <num> enables an optional ldap connect retry loop with
87 the specified number of retries with a one second sleep between each try
88 during the initial startup of the dhcp server.
89 It allows to catch the condition, that the (remote) ldap server is not yet
90 started at the start time of the dhcp server.
91
92 All of these parameters should be self explanatory except for the ldap-method.
93 You can set this to static or dynamic. If you set it to static, the
94 configuration is read once on startup, and LDAP isn't used anymore. But, if
95 you set this to dynamic, the configuration is read once on startup, and the
96 hosts that are stored in LDAP are looked up every time a DHCP request comes
97 in.
98
99 When the optional statement ldap-debug-file is specified, on startup the DHCP
100 server will write out the configuration that it generated from LDAP. If you
101 are getting errors about your LDAP configuration, this is a good place to
102 start looking.
103
104 The next step is to set up your LDAP tree. Here is an example config that will
105 give a 10.100.0.x address to machines that have a host entry in LDAP.
106 Otherwise, it will give a 10.200.0.x address to them. (NOTE: replace
107 dc=ntelos, dc=net with your base dn). If you would like to convert your
108 existing dhcpd.conf file to LDIF format, there is a script
109 dhcpd-conf-to-ldap that will convert it for you. Type
110 dhcpd-conf-to-ldap --help to see the usage information for this script.
111
112 # You must specify the server's host name in LDAP that you are going to run
113 # DHCP on and point it to which config tree you want to use. Whenever DHCP
114 # first starts up, it will do a search for this entry to find out which
115 # config to use
116 dn: cn=brian.ntelos.net, dc=ntelos, dc=net
117 objectClass: top
118 objectClass: dhcpServer
119 cn: brian.ntelos.net
120 dhcpServiceDN: cn=DHCP Service Config, dc=ntelos, dc=net
121
122 # Here is the config tree that brian.ntelos.net points to.
123 dn: cn=DHCP Service Config, dc=ntelos, dc=net
124 cn: DHCP Service Config
125 objectClass: top
126 objectClass: dhcpService
127 dhcpPrimaryDN: dc=ntelos, dc=net
128 dhcpStatements: ddns-update-style none
129 dhcpStatements: default-lease-time 600
130 dhcpStatements: max-lease-time 7200
131
132 # Set up a shared network segment
133 dn: cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
134 cn: WV
135 objectClass: top
136 objectClass: dhcpSharedNetwork
137
138 # Set up a subnet declaration with a pool statement. Also note that we have
139 # a dhcpOptions object with this entry
140 dn: cn=10.100.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
141 cn: 10.100.0.0
142 objectClass: top
143 objectClass: dhcpSubnet
144 objectClass: dhcpOptions
145 dhcpOption: domain-name-servers 10.100.0.2
146 dhcpOption: routers 10.100.0.1
147 dhcpOption: subnet-mask 255.255.255.0
148 dhcpOption: broadcast-address 10.100.0.255
149 dhcpNetMask: 24
150
151 # Set up a pool for this subnet. Only known hosts will get these IPs
152 dn: cn=Known Pool, cn=10.100.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
153 cn: Known Pool
154 objectClass: top
155 objectClass: dhcpPool
156 dhcpRange: 10.100.0.3 10.100.0.254
157 dhcpPermitList: deny unknown-clients
158
159 # Set up another subnet declaration with a pool statement
160 dn: cn=10.200.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
161 cn: 10.200.0.0
162 objectClass: top
163 objectClass: dhcpSubnet
164 objectClass: dhcpOptions
165 dhcpOption: domain-name-servers 10.200.0.2
166 dhcpOption: routers 10.200.0.1
167 dhcpOption: subnet-mask 255.255.255.0
168 dhcpOption: broadcast-address 10.200.0.255
169 dhcpNetMask: 24
170
171 # Set up a pool for this subnet. Only unknown hosts will get these IPs
172 dn: cn=Known Pool, cn=10.200.0.0, cn=WV Test, cn=DHCP Service Config, dc=ntelos, dc=net
173 cn: Known Pool
174 objectClass: top
175 objectClass: dhcpPool
176 dhcpRange: 10.200.0.3 10.200.0.254
177 dhcpPermitList: deny known clients
178
179 # Set aside a group for all of our known MAC addresses
180 dn: cn=Customers, cn=DHCP Service Config, dc=ntelos, dc=net
181 objectClass: top
182 objectClass: dhcpGroup
183 cn: Customers
184
185 # Host entry for my laptop
186 dn: cn=brianlaptop, cn=Customers, cn=DHCP Service Config, dc=ntelos, dc=net
187 objectClass: top
188 objectClass: dhcpHost
189 cn: brianlaptop
190 dhcpHWAddress: ethernet 00:00:00:00:00:00
191
192 You can use the command ldapadd to load all of these entries into your LDAP
193 server. After you load this, you should be able to start up DHCP. If you run
194 into problems reading the configuration, try running dhcpd with the -d flag.
195 If you still have problems, edit the site.conf file in the DHCP source and
196 add the line: COPTS= -DDEBUG_LDAP and recompile DHCP. (make sure you run make
197 clean and rerun configure before you rebuild).
198
199 DHCPv6 requires a separate instance of the dhcpd server from the
200 DHCPv4 server.
201
202 It is convenient to use distinct LDAP login DNs for the two servers,
203 and setup LDAP access restrictions in the LDAP server, so that each
204 DHCP server only has access to its own data.
205
206 You will need to create a separate configuration file,
207 call it /etc/dhcpd6.conf. For example:
208
209 ldap-server "localhost";
210 ldap-port 389;
211 ldap-username "cn=DHCPv6 User, dc=ntelos, dc=net";
212 ldap-password "blahblah";
213 ldap-base-dn "dc=ntelos, dc=net";
214 ldap-method dynamic;
215 ldap-debug-file "/var/log/dhcp-ldap-startup.log";
216
217 And use these command line arguments to dhcpd:
218
219 dhcpd eth... -6 -cf /etc/dhcpd6.conf -pf /var/run/dhcpd6.pid -lf /var/lib/dhcpd6/dhcpd.leases
220
221 For DHCPv6, the client configuration is the same, but substitute the
222 Client ID for the Ethernet hardware address. Here is an example of a
223 host definition for a DHCPv6 client:
224
225 dn: cn=examplehost,cn=XXXX:XXXX:XXXX:XXXX::/64,cn=Network-eth1,cn=DHCPv6,dc=example,dc=com
226 objectClass: top
227 objectClass: dhcpHost
228 cn: examplehost
229 dhcpClientId: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
230 dhcpStatements: fixed-address6 XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX
231 option host-name "examplehost.ipv6.example.com"
232 option domain-name "ipv6.example.com"
233