Automatic way to increase zone file serial number by one in BIND9

binddomain-name-system

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.

Best Answer

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.