Today I had to migrate a customer’s DNS server to a new server… This because the old server (a very old plesk instance) was end of life.
As I have very good experiences with PowerDNS, we decided to migrate from Bind (Named) to PowerDNS.
PowerDNS provides you with the utilities to do so, but I did not find a straight forward way to export/import zones from Bind into PowerDNS.
Installation of PowerDNS and PowerAdmin (a PowerDNS Gui) is out of the scope of this document, so I assume you already have a working PowerDNS server.
These are the steps I had to perform to migrate from the Plesk 8.2 server to PowerDNS:
1) First of all, you need to allow zone transfer (AXFR) on your bind server from your new PowerDNS server IP. You need to change the contents of /etc/named.conf in something like this (add the allow-transfer lines in the Options block.
1 2 3 4 5 6 |
options { ... allow-transfer {xx.xx.yy.zz;}; allow-transfer {aa.bb.cc.dd;}; ... }; |
2) Reload or restart named to take effect:
1 |
/etc/init.d/named reload |
3)Test a zone transfer, eg:
1 |
dig AXFR @old.nameserver.tld test.tld |
4) Now that you know zone transfer is working, create a list of domains that your Bind server is ‘serving’. In my case i have to remove some extra .lock and .saved_by_psa files from my listing. If you use this tutorial, your command can look differently of course.
1 |
ls -1 /var/named/run-root/var/ | grep -v .lock | grep -v .saved_by_psa > /root/domainlist.dns |
If needed: check if the domains in bind still use your old nameservers… (do not polute your new powerDNS server :))
1 |
cat /root/domainlist.dns | while read domein; do echo $domein; dig ns $domein +short ; done > /root/domain_nsusage.txt |
Then delete all domains from /root/domainlist.dns if they not valid anymore
5) Import your zones by:
a) Create Zone Import SQL scripts
1 |
for zone in `cat /root/domainlist.dns` ; do dig AXFR @old.nameserver.tld $zone > /tmp/$zone.sql ; zone2sql --gmysql --zone-name=$zone --zone=/tmp/$zone.sql > /tmp/import.$zone; done |
From these generated files, remove duplicate SOA records from all import files:
1 |
cd /tmp && for zone in `ls -1 import.*`; do sort $zone| uniq > fresh.$zone; done |
If needed: change TTLs:
1 |
sed -i 's/86400,/900,/g' /tmp/import.*.sql |
Depending if your imported zones need to be set as NATIVE or MASTER
1 |
sed -i 's/NATIVE/MASTER/g' /tmp/import.*.sql |
Change extra stuff with sed, like hostmaster and so on
b) Test import into mysql
1 |
mysql -uroot -p powerdns < /tmp/import.testdomain.tld.sql |
c) Verify in poweradmin and drop the imported zone (or you’ll get an import error on the next step, which is not bad or something… but hey :))
d) Import all your zones, if you like what you have done:
1 |
for zone in `ls -1 /tmp/import.*.sql`; do mysql powerdns < /$zone; done |
hi nicovs
im trying to follow your steps but unfortuneatly i have issues in remove duplicate soa
for zone in
ls -1 /tmp/import.*
; do sort import.$zone| uniq > fresh.$zone; doneoutput:
sort: error : import./tmp/import.www.grupovidela.com: File or directory do not exist
Do you know how to fix it? I have tested lot of modifications without success
great work by the way!
Oops… My bad… Updated the post: it should be: cd /tmp && for zone in
ls -1 import.*
; do sort $zone| uniq > fresh.$zone; done