How to import authoritative (primary) zone data into Lion Server DNS? Our current authoritative DNS server suffers from random reboot issues.

That is why we would like to import our DNS zones into a Lion DNS server (BIND). We could not find an option to import DNS records via zone transfer (AXFR).

How to import DNS zone data into Lion Server DNS?
There is a Bash/Terminal/Command line command that might help to import DNS zone data into Mac OS X Lion its DNS server.

$ sudo serveradmin settings dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:allowZoneTransfer = yes


Issuing this command creates a zone file (in this example for "domain.tld") with some default settings and without any host records.

$ sudo serveradmin settings dns | grep dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:allowZoneTransfer = yes
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:aliases = _empty_array
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:expire = 604800
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:serial = 2013122701
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:allow-update = no
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:adminEmail = "admin@domain.tld"
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:machines = _empty_array
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:nameservers = _empty_array
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:refresh = 86400
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:mailExchangers = _empty_array
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:reverseMappings = _empty_array
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:retry = 3600
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:timeToLive = 345600
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:serviceRecords = _empty_array
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:bonjourRegistration = no
dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:domain.tld:name = "domain.tld"


The created zone file with default settings now looks like:

$ cat /private/var/named/db.domain.tld
domain.tld.           10800 IN SOA  domain.tld. admin.domain.tld. (
                            2013122701 ; serial
                            86400      ; refresh (1 day)
                            3600       ; retry (1 hour)
                            604800     ; expire (1 week)
                            345600     ; minimum (4 days)
                            ) 


With the command below you can create (import) default DNS zone records for each domain that is listed on a separate line in a file named "domains.txt".

$ while read line; do sudo serveradmin settings dns:views:_array_id:com.apple.ServerAdmin.DNS.public:primaryZones:_array_id:"$line":allowZoneTransfer = yes; done &lt; domains.txt


And when your source DNS server allows zone transfer (axfr) the script below can be used to copy the DNS zone data from the old server to the new Mac OS X DNS server.

$ authNS=ns1.mydns.net;while read line; do dig +noall +multiline +answer +onesoa -t axfr "$line" @"$authNS" | sudo tee /private/var/named/db."$line"; done &lt; domains.txt


Note: you need to change "ns1.mydns.net" to the host name or IP address of the server you are trying to import from.