Skip to content

Instantly share code, notes, and snippets.

@udienz
Last active May 31, 2022 14:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save udienz/335f96a6a72ea9bd93fd to your computer and use it in GitHub Desktop.
Save udienz/335f96a6a72ea9bd93fd to your computer and use it in GitHub Desktop.
Powerdns bulk create domain to sql records
#!/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
@xpufx
Copy link

xpufx commented Feb 7, 2017

Wouldn't it be cleaner to use pdnsutils to do the actual modifications? That would (probably) also make this work with different backends. I am actually looking for a tool that can import from /etc/hosts or similar formats into pdns. I would expect pdns to provide such a tool but haven't found it yet. By the way I am talking about PowerDNS. Please ignore if this is the other pdnsd.

@MagicMagnate
Copy link

this is prior to pdns version 4 which doesn't have pdnsutil

Copy link

ghost commented Apr 29, 2021

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.

@cmaurand
Copy link

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