I’d like to update a zone file from a CLI script - change the IP address for a single host, and update the “last-updated” SOA serial entry.
What’s the best way to do this? Are there any existing tools that help automated zone file editing without breaking them and that keep existing formatting?
It’s very difficult to write tools to edit zone files, because the file format is so lenient.
If you just want to update a specific record in your zone file, then it’s easy to do that with the usual tools like sed/awk/perl, because you know how your zone file is structured. This is also the best way to keep your zone file ordering and comments.
Another way would be to write a script in python, using the “dnspython” module. You would load the zone into memory, update the record(s) you want to (including serial number), and then write out the zone back to disk, but you would lose all the comments and ordering.