ISC DHCPD with OpenLDAP backend
Info stolen from: http://mageconfig.blogspot.nl/2014/10/configure-isc-dhcp-server-with-openldap.html
Need to validate and test.
Install ISC DHCP Server
. Install required packges:
apt-get install dhcp3-server-ldap
Install schema into OpenLDAP
zcat /usr/share/doc/isc-dhcp-server-ldap/dhcp.schema.gz > /etc/ldap/schema/dhcp.schema
Create a file called dhcp.conf
containing:
- dhcp.conf
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
Configure required 4 main components
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
Create tree for DHCP configuration
- dhcp.ldif
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
Add DHCP server entries
- dhcpserver.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
Add DHCP service entries
- dhcpservice.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=192.168.1.0, cn=config, ou=dhcp,dc=example,dc=com cn: 192.168.1.0 objectClass: top objectClass: dhcpSubnet objectClass: dhcpOptions dhcpNetMask: 24 dhcpRange: 192.168.1.150 192.168.1.200 dhcpStatements: default-lease-time 600 dhcpStatements: max-lease-time 7200 dhcpOption: netbios-name-servers 192.168.1.16 dhcpOption: subnet-mask 255.255.255.0 dhcpOption: routers 192.168.1.1 dhcpOption: domain-name-servers 192.168.1.11 dhcpOption: domain-name "example.com"</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 192.168.1.111 </file> <code> ldapadd -x -H ldap://localhost/ -D cn=admin,dc=example,dc=com -W -f host.ldif
Configure DHCPD to communicate with OpenLDAP
- /etc/dhcp/dhcpd.conf
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. (http://muzso.hu/2010/04/26/fixing-bdb_equality_candidates-errors-on-your-openldap-server)
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