If you’ve ever administered a DNS (name server), than you know that serial numbers mean a lot. But what happens when you have several [hundreds|thousands] of zone that you need to make a mass-change to. That’s easy enough, there’s tons of ways to do that with sed, awk, or simple tools like “replace”. However, once you’ve done the easy work, you still need to update all the serial numbers as well. Here’s how I saved myself hours of manual labor:
If you’re even reading this article, it’s expected that you at least know that a serial number is in the form YYYYMMDDNN where NN is the update number for that day. So the serial number from my post today would be 2011031900.
Now here’s how you tell sed what you want done (note, this formula assumes that your previous serial numbers were post-2000):
# sed -i ‘s/20[0-9][0-9]\{7\}/2011031900/g’ *.db
This says to replace any text starting with 20+[any two numbers 0-9] and followed by another 7 digits with the string: 2011031900
Problem solved, check out your zones now (provided they end in the standard format of domain.tld.db).
Tweet
Works like a charm, thanks for the snippet. You might need to add -E under FreeBSD 9.X to get sed to behave like the GNU sed.