modifying IPs and serials in a bunch of dns data files

Harold Pritchett harold at uga.edu
Tue Feb 13 16:49:36 UTC 2001


Maximo Ramos wrote:
> 
> Hi
> 
> I hope the subject is pretty clear, I have plenty of dns-data files in
> /var/named/data1 ... Plenty of domains pointing to the same IP ...
> But my ISP informed me of a change in my static IP, I was about to write a
> script with sed to change all the old IP to the new one, but then I
> realized the issue of the serial number.
> 
> My dns confs are very simple:
> 
> @               IN SOA XXX.XXXXXXXXXXX.XXX. XXXX.XXXXXXXX.XXX. (
>                         5       ; serial, todays date + todays serial
>                         10800   ; refresh, seconds bla, bla ...
> 
> Is there any unix tool I can use to detect the serial number and
> increment it by one? I use RH Linux if that matters ...

The following perl script should do what you want.  It looks for the
string "Serial" on the serial number line.  You may have to modify this
to get it to select the right line to update the serial.  The other
condition will replace all occurrences of 1.2.3.4 with 5.6.7.8

No guarantees.  I hacked this together out bits of other scripts.

Save it as "doit", make it executable, and then execute it in a loop
as "./doit domainfilename" and it should take care of what you want.  It
will rename the original file as domainfilename.old.

Hope it helps

Harold
------------------------------
#!/usr/bin/perl -i.old
#

$date  = `date +%Y%m%d`;
chop $date;

while (<>) {
if (/Serial/) { $rdate = substr($_,index($_,'20'),8);
                if ($rdate == $date) 
                    {$ser = substr($_,index($_,'20')+6,4);
                     $ser++;
                     substr($_,index($_,'20')+6,4) = $ser;
                    }
                else 
                    {s/\d\d\d\d\d\d\d\d/$date/;
                     substr($_,index($_,'20')+8,2) = '01';
                    }; 
              }
/1\.2\.3\.4/ && s/1\.2\.3\.4/5.6.7.8/;
print;
}
-------------------------------------------

$ ./doit zzz
$ diff zzz zzz.old
6c6
<                                         2001021301      ; Serial 
---
>                                         1996060301      ; Serial 
22c22
< xxx             in      a               5.6.7.8
---
> xxx             in      a               1.2.3.4


More information about the bind-users mailing list