How to incremental serial number in dns zone?

astopy

Well-Known Member
Apr 3, 2003
166
0
166
cPanel Access Level
Root Administrator
If you're editing it in WHM, it'll increment the serial number automatically. If you're editing it by hand for some reason, just increment the serial number by hand as well.
 

vanessafan

Member
May 26, 2011
6
0
51
for a given file domain.com.db how do you do this?
maybe via the command line?
i need to do it for a couple hundred domains
 

astopy

Well-Known Member
Apr 3, 2003
166
0
166
cPanel Access Level
Root Administrator
The format of the zone files should be predictable, so you should be able to write a script to edit them all. There isn't an easy, ready-made way of doing it as far as I know.

The other way would be to edit each file with vim, emacs, nano, whatever. That would obviously be pretty time consuming though.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,229
463
Hello :)

i need to do it for a couple hundred domains
This could be achieved using a Perl command like the one posted below. Please notice that /var/named is backed up before running this command so it can be restored if any errors occur:

Code:
# cp -a /var/named /var/named-backup 
# find /var/named/*.db -mtime -1 -exec perl -pi -e 'if (/^\s+(\d{10})\s+;\s+serial/i) { my $i = $1+1; s/$1/$i/;}' '{}' \;
This will increment the serial for all DNS zones within the /var/named directory.

Thank you.