ISC DHCPD with OpenLDAP backend

. Install required packges:

apt-get install dhcp3-server-ldap
zcat /usr/share/doc/isc-dhcp-server-ldap/dhcp.schema.gz > /etc/ldap/schema/dhcp.schema

Create a file called dhcp.conf containing:

include /etc/ldap/schema/dhcp.schema
mkdir /tmp/dhcp
slaptest  -f /tmp/dhcp.conf  -F /tmp/dhcp

Cleanup resulting ldiff file /tmp/dhcp/cn\=config/cn\=schema/cn\=\{0\}dhcp.ldif, remove below mentioned (similar) lines:

structuralObjectClass: olcSchemaConfig
entryUUID: 9bcf5d1c-ee67-1033-8cfe-8d23f897bb77
creatorsName: cn=config
createTimestamp: 20141022184725Z
entryCSN: 20141022184725.031859Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20141022184725Z

Update following (similar) lines:

dn: cn=dhcp,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: dhcp

Load the ldif into OpenLDAP:

ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /tmp/dhcp/cn\=config/cn\=schema/cn\=\{0\}dhcp.ldif
DHCP Server itself need to define in top level, below the base DN (dc=example,d=com).
DHCP Service
DHCP Subnet definition.
DHCP Host definition
dn: ou=dhcp,dc=example,dc=com
ou: dhcp
objectClass: top
objectClass: organizationalUnit
description: DHCP Servers
ldapadd  -x -H ldap://localhost/ -D cn=admin,dc=example,dc=com -W -f dhcp.ldif
dn: cn=server,ou=dhcp,dc=example,dc=com
cn: server
objectClass: top
objectClass: dhcpServer
dhcpServiceDN: cn=config,ou=dhcp,dc=example,dc=com
ldapadd  -x -H ldap://localhost/ -D cn=admin,dc=example,dc=com -W -f dhcpserver.ldif
dn: cn=config, ou=dhcp,dc=example,dc=com
cn: config
objectClass: top
objectClass: dhcpService
dhcpPrimaryDN:  cn=server,ou=dhcp,dc=example,dc=com
dhcpStatements: ddns-update-style none
dhcpStatements: get-lease-hostnames true
dhcpStatements: use-host-decl-names true
ldapadd  -x -H ldap://localhost/ -D cn=admin,dc=example,dc=com -W -f dhcpservice.ldif<code>

==== Add DHCP subnet information now ====
<file - dhcpsubnet.ldif>dn: cn=, cn=config, ou=dhcp,dc=example,dc=com
objectClass: top
objectClass: dhcpSubnet
objectClass: dhcpOptions
dhcpNetMask: 24
dhcpStatements: default-lease-time 600
dhcpStatements: max-lease-time 7200
dhcpOption: netbios-name-servers
dhcpOption: subnet-mask
dhcpOption: routers
dhcpOption: domain-name-servers
dhcpOption: domain-name ""</file>
<code>ldapadd  -x -H ldap://localhost/ -D cn=admin,dc=example,dc=com -W -f dhcpsubnet.ldif<code>

==== Add a Host entry which bind Mac to Ip ====
<file - host.ldif>
dn: cn=client01, cn=config, ou=dhcp,dc=example,dc=com
cn: client01
objectClass: top
objectClass: dhcpHost
dhcpHWAddress: ethernet 00:16:3e:3d:eb:87
dhcpStatements: fixed-address
ldapadd  -x -H ldap://localhost/ -D cn=admin,dc=example,dc=com -W -f host.ldif
ldap-server                 "localhost";
ldap-port                   389;
# We do an anonymous bind
# ldap-username             "cn=directorymanagerloginname";
# ldap-password             "mypassword";
ldap-base-dn                "ou=dhcp,dc=example,dc=com";
ldap-method                 static;
ldap-debug-file             "/var/log/dhcp-ldap-startup.log";
ldap-dhcp-server-cn         "server"

Before starting DHCP server follow below steps too. Make sure to shut down slapd daemon.

/etc/init.d/slapd stop
vim /etc/ldap/slapd.d/cn\=config/olcDatabase\=\{1\}hdb.ldif

Add below lines after the line with “olcDbIndex: objectClass eq” for missing indexes. After that run the “slapindex” for reindexing and start the slapd daemon. (

olcDbIndex: cn eq
olcDbIndex: gidNumber eq
olcDbIndex: memberUid eq
olcDbIndex: uid eq
olcDbIndex: uidNumber eq
olcDbIndex: uniqueMember eq
sudo -u openldap slapindex -F /etc/ldap/slapd.d/
/etc/init.d/slapd start

Finally restart the DHCP server and now it should be ready to server with basic configurations.

/etc/init.d/isc-dhcp-server restart

Current dynamic leases are stored in file /var/lib/dhcp/dhcpd.leases

  • infra/dhcp_openldap.txt
  • Last modified: 20/11/2021 00:29
  • by harm