ldap2dns is a program to read DNS (Domain Name Service) records from an LDAP directory and format them into flat files suitable for TinyDNS (or Bind).
ldap2dns reduces all kind of administration
overhead: No more flat file editing, no more zone file
editing. After having installed ldap2dns, the
administrator only has to modify the data stored in the
LDAP directory.
Optionally access control can be configured for each zone,
GUIs can be more easily implemented, and add all other kind
of zone and resource record information can be managed
without interfering with the DNS server.
ldap2dns is designed to write ASCII data files used
by tinydns
from the djbdns
package, but also may be used to write zone db files used
by named as found in the BIND package.
ldap2dns is known to compile and run under Linux and Solaris using GCC or Sun Studio C Compiler.
Often it is desirable to store DNS information in a database rather than in flat text files. This can greatly help to reduce administration overhead since associate information such as billing contact, account management, etc. can be stored and processed inside the same database. Also due to the nature of DNS, information must be stored redundantly on two or more hosts. The classical data replication through zone transfer is unreliable, insecure and difficult to administer.$ sudo rpm -Uhv ldap2dns.rpmReplace "ldap2dns.rpm" with the file you have downloaded.
$ gzcat ldap2dns.tar.gz | tar x $ cd ldap2dns-version $ make $ sudo make install
include /etc/openldap/schema/ldap2dns.schemaNow restart your LDAP server.
$ ldapadd -D "binddn" -w password < example.ldifReplace 'myorg' and 'binddn' with whatever is appropriate on Your system. Start a search and see if something was added
$ ldapsearch -D "binddn" "objectclass=dnsrrset"
$ ./ldap2dns -D "binddn" [ -b "searchbase" ] [ -w passwd ] -o data -o db -LThis should create a 'data' file, a 'corp.local.db' file and should print the DNS content.
ATTRIBUTE | VALUE | Comment |
---|---|---|
objectclass | DNSzone | required |
cn | common name | required |
DNSzonename | Name of the zone | required, multivalued |
DNSserial | Serial number of SOA | optional |
DNSrefresh | Refresh time of SOA | optional, only used for zone transfers |
DNSretry | Retry time of SOA | optional, only used for zone transfers |
DNSexpire | Expire time of SOA | optional, only used for zone transfers |
DNSminimum | Minimum time to live | optional, only used for zone transfers |
DNSadminmailbox | Hostmaster's contact address | optional |
DNSzonemaster | Primary nameserver for this zone | optional |
DNStype | SOA | must be SOA |
DNSclass | IN | must be IN |
DNSttl | time to live | optional, only used with tinydns |
DNStimestamp | timestamp | optional, only used with tinydns |
ATTRIBUTE | VALUE | Comment |
---|---|---|
objectclass | DNSrrset | required |
cn | common name | required |
DNSdomainname | Name of this record | optional, relative to zonename |
DNSipaddr | IP address | optional, mutivalued |
DNScname | Canonical name | optional, without ending dot relative to zonename |
DNSpreference | integer | optional, only used for MX records |
DNStype | A, CNAME, NS, MX, PTR or TXT | must be any valid record type |
DNSclass | IN | must be IN |
DNSttl | time to live | optional, only used with tinydns |
DNStimestamp | timestamp | optional, only used with tinydns |
DNSsrvpriority | SRV Priority | optional, defaults to 0 for SRV records |
DNSsrvweight | SRV Weight | optional, defaults to 0 for SRV records |
DNSsrvport | SRV Port | Required for SRV records |
cn=domainname,cn=zonename,...
-D binddn specify the distinguished name to bind to the LDAP directory -w bindpasswd use bindpasswd as password for simple authentication -b searchbase use searchbase as starting point for search instead default -o data generate a "data" file to be processed by tinydns-data -o db for each zone generate a "<zonename>.db" file to be used by named -L[filename] print output in LDIF format to [filename] or stdout for reimport -h host specify the hostname of LDAP directory. Default is localhost -p port portnumber to connect to LDAP directory. Defaults is 389 -H ldapURI URI for LDAP server (examples: ldap://hostname or ldaps://hostname:636) -v run in verbose mode -vv even more verbose -V print version and exit -u numsecs update DNS data every numsecs. -t timeout timeout for LDAP searches, in seconds -M reclimit Limit LDAP results to reclimit number of records.ldap2dns and ldap2dnsd recognize the following environment variables:
$ ldap2dns -D "binddn" [ -w passwd ] -b "searchbase" \ -o data -e "cd /var/tinydns/root && /usr/bin/tinydns-data"This generates a data file which is converted into a data.cdb by tinydns-data as soon as ldap2dns detects a modification in the LDAP directory. The password is required if You restrict read queries to authenticated users only. Test with
$ dnsq any corp.local ipaddrReplace ipaddr with whatever You configured tinydns to listen to. If You are a BIND user, run ldap2dns in /var/named with
$ ldap2dns -D "binddn" -w passwd -b "searchbase" \ -o db -e "kill -HUP `cat /var/run/named-pid`"Do not forget to add You primary definition to your named.conf file. Your named should be restarted automatically as soon as ldap2dns detects a modification in the LDAP directory. If bind is not restarted, do so with
# kill -HUP PIDNow run
$ nslookup - localhost > ns1.corp.localNote that nslookup only works with tinydns if your nameserver resolves its IP-address backwards. When ldap2dns is invoked as ldap2dnsd, the program starts as backgound-daemon and continuously checks for modifications in the LDAP directory. If the the daemon sees a modification in the DNSserial numbers it updates the data or .db files, depending what kind of output was configured. This check is done about once a minute and is configurable.
# groupadd -r ldap2dns # useradd -r -d /dev/null -s /bin/false -c "ldap2dns Daemon" \ -g ldap2dns ldap2dns # groupadd -r l2dnslog # useradd -r -d /dev/null -s /bin/false -c "ldap2dns Logger" \ -g l2dnslog l2dnslog
# cd /etc # ldap2tinydns-conf ldap2dns l2dnslog /etc/ldap2dns /etc/tinydns/rootThe syntax is close to tinydns-conf except that you will also need to specify the path to the root directory for tinydns. This is the directory that holds the data file.
# ln -s /etc/ldap2dns /service/ldap2dnsAfter a few seconds daemontools starts ldap2dnsd which itself generates data files whenever a modification is commited into the LDAP directory. A perl-script import.pl is contained in this package. Edit the first lines of the script to conform to Your configuration. If You have installed the Perl packages Net::LDAP and Net::DNS skip the following lines, otherwise do
# perl -MCPAN -e 'shell' (...snip...) > install Net::DNS > install Net::LDAPNow check that Your nameserver allows zone transfers to your host and run the import script:
$ echo 'primary mydomain.org ' | ./import.plfor a single domain or
# cat named.boot | ./import.plto populate Your LDAP directory. Use the supplied data2ldap.pl in the scripts/ directory
$ data2ldap.pl data data.ldif ou=DNS,dc=example,dc=comMore to come...