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
@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