Last active
May 31, 2022 14:06
-
-
Save udienz/335f96a6a72ea9bd93fd to your computer and use it in GitHub Desktop.
Powerdns bulk create domain to sql records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
host=localhost | |
passwd=17agustus | |
db=pdns | |
user=pdns | |
list=/tmp/blacklists/porn/domains | |
sqlin="mysql -u $user -p$passwd -h $host $db" | |
sql_new_domain () { | |
$sqlin -e "INSERT INTO domains (id, name, master, last_check, type, notified_serial, account) VALUES ('', '$domain', NULL, NULL, 'NATIVE', NULL, NULL);" | |
} | |
search_dom () { | |
$sqlin -N -B -e "SELECT id FROM domains WHERE name LIKE '$domain'" | |
} | |
cat $list | while read domain | |
do | |
sql_new_domain | |
id=$(search_dom) | |
echo "domain $domain have $id" | |
echo " | |
INSERT INTO \`records\` (domain_id,name,type,content,ttl,prio,change_date) VALUES | |
('$id', '$domain', 'SOA', 'pdns.sby.rad.net.id hostmaster.sby.rad.net.id $(date +%Y%m%d%H) 10800 1800 604800 86400', '3600', '0', '$(date +%s)'), | |
('$id', '$domain', 'A', '127.0.0.1', '3600', '0', '$(date +%s)'), | |
('$id', '$domain', 'NS', 'localhost', '3600', '0', '$(date +%s)'), | |
('$id', '$domain', 'MX', '$domain', '3600', '0', '$(date +%s)'), | |
('$id', '*.$domain', 'A', '127.0.0.1', '3600', '0', '$(date +%s)');" | $sqlin | |
# pdnssec rectify-zone $domain | |
done |
Not really important I guess for the regular setups. Indeed with another back-end the tool is nice too. But if you just need a shell implementation with mysql this works great. Using it too with some little adjustments.
was looking for the correct value to set the domain as a master on the master. I was looking for the value for the column. powerdns documentation on this subject is scant.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is prior to pdns version 4 which doesn't have
pdnsutil