7

I've a BIND9 server with a lot of zones and I need to increase the serial number of the zone files by one. Some zones are using the YYYYMMDDXX format but other zones just increase it by one, as they are dynamic DNS zones, so updating all by one would do the job for me.

There's a way to do this? I tried with sed but I'm lacking knowledge to do this automatically.

1
  • Did any of the answers address your problem? If not, can you provide the solution you ended up using? This prevents the question from showing up in the unanswered list.
    – Andrew B
    Sep 21, 2014 at 8:09

6 Answers 6

3

This would be pretty difficult to do in 'sed' but it is fairly easy in 'awk'.

 awk '{ if ( $0 ~ /[\t ]SOA[\t ]/ ) $7=$7+1; print}'

If it is an SOA line ("SOA" with a space or tab before and after it) then increment field 7 (serial number). Print every line.

This only increments the serial number which is what was asked, however you'll still need to trigger a reload and notifies to the secondary servers to propagate the changes.

1
  • I don't need it anymore, but it was what I was looking for back in the day. Thanks. Jan 26, 2019 at 19:31
2

Since the bind zone format is pretty flexible any simple text manipulation tools might be a bit dangerous.

One method to accomplish your goal, might be to enable dynamic updates for all your zones, with acls limiting access from the local machine only. Then simply add add, and then remove a temporary record in each zone with nsupdate. Bind will deal with updating the serial for you.

2
  • 1
    Yep, it's possible, but doing this will destroy my custom formatting of zone files, right? Jul 30, 2014 at 1:49
  • @ViníciusFerrão Bind would rewrite the files, yes. Jul 30, 2014 at 5:42
1

If you are dealing with a one-off event and need to force a transfer, then rndc retransfer is the tool of choice for ignoring serial numbers and just doing it. This approach should not be used for day to day work (it throws off serial number accuracy), but sometimes the need for working out of band is greater.

A loop around the following should do the trick:
rndc -s ${someslave} -k ${yourkey} retransfer ${i}.example.com

(as a side note, this is also the preferred way of fixing a serial number when it is incremented into the future)

2
  • 1
    Just a note that retransfer is to be run from the slaves, not from master. Apr 17, 2020 at 20:22
  • @FernandoFabreti And to further clarify, the retransfer operation is what must be run by the secondary. It is fine to execute rndc on the master provided that you are using the -s option to direct the command at the secondary server that needs to retransfer the zone.
    – Andrew B
    Apr 20, 2020 at 5:25
0

If the SOA's of all the domains are going to be the same, just put the SOA in a separate file, db.soa or something, and then include it in each zone:

$INCLUDE db.soa

That way there's only one place to have to increment. Also, depending on exactly how you're implementing whatever all you're doing, it may make more sense to use UNIX epoch time as the serial instead of incrementing by one each time. You could create a script, say touch-zones.sh that would overwrite the db.soa file and use the current unix timestamp in the serial. all zones would then by inclusion have their serials incremented.

1
  • It wouldn't work with the dynamic zones, but other than that it would be a possibility. Jul 30, 2014 at 5:44
0

I've used a utility called h2n to manipulate BIND zone files. I first learned about it the O'Reilly DNS and BIND book. You want the "-y" option.

0

A nice HOWTO about this is at:http://www.microhowto.info/howto/reset_the_serial_number_of_a_dns_zone.html

This is also the recommended way in the DNS & BIND book (2006 ed.). The important thing to understand is that DNS SOA serial numbers "wrap around". Unfortunately, the typical YYYYMMDDXX serial numbers breaks with dynamic updates and I think that it might be better to dispense with that altogether, and use montonically increasing serial numbers and keeping zone files in version control.

For, the specific problem at hand, I think the larger challenge would be to identify the number that would make all zones think is a larger one and synchronize them all to that.

Similar questions on SX:

  1. Changing DNS serial number to be in the past
  2. https://unix.stackexchange.com/questions/36869/how-can-i-reset-or-lower-the-serial-used-in-bind-dns-servers-soa-record

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .