Skip to content

Instantly share code, notes, and snippets.

@jbgo
Created April 5, 2013 20:39
Show Gist options
  • Save jbgo/5322446 to your computer and use it in GitHub Desktop.
Save jbgo/5322446 to your computer and use it in GitHub Desktop.
Bulk DNS record updates with ProBIND (via a few MySQL queries)

Do you have a pre-existing ProBIND installation with thousands of zones and you would like to change the IP address for hundreds of A records?

Here is one way you could do it without spending hours clicking through the GUI. Ok, so I'm circumventing probind for the most part and going straight to MySQL, since probind is basically a CRUD app around a few tables in a databse.

1. Given a list of domains, preview the records you want to update.

select zones.id, zones.domain, zones.updated, records.id, records.zone, records.domain, records.type, records.data from records
inner join zones on zones.id = records.zone
where (records.domain = '@' or records.domain = 'www') and records.type = 'A' and records.data = '123.ip.add.rss'
  and records.zone in (select id from zones where domain in ('a.list', 'of.domains', 'to.update'));

2. Update the matching records.

The number of records updated should match the number of rows returned in query #1.

update records set data = '123.the.new.ip', mtime = now()
where (records.domain = '@' or records.domain = 'www') and records.type = 'A' and records.data = '123.ip.add.rss'
  and records.zone in (select id from zones where domain in ('a.list', 'of.domains', 'to.update'));

3. Check your work.

select * from records where mtime > (now() - interval 5 minute);
select distinct zone from records where mtime > (now() - interval 5 minute);

4. Mark the zones for these records as having been updated.

This could take awhile, so be patient. The number of records updated should match the number of rows returned in the second query for step #3.

update zones set updated = 1 where id in (
  select distinct zone from records where mtime > (now() - interval 5 minute));

5. Check your work again.

select * from zones where updated = 1;

At this point you can log in to probind at http://your.server.host/probind/ and you should see a list of pending changes. Feel free to click through those and make sure they look like what you are expecting. Assuming everything worked correctly, you still have to push the changes to our name servers. Click the Push updates tab then click the Start Update button. Be patient while the new zone files are generated and updated on the nameservers. When finished, scroll to the bottom and click the link to view the logs to verify that all of your changes were made successfully.

@jbgo
Copy link
Author

jbgo commented Apr 5, 2013

The queries shown here are specific to my use case. You will have to modify them to work correctly for your situation. Just remember, get your selects right before running your updates! I warned you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment