Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Fixing up DNS Zone Files

by marius (Hermit)
on Jan 30, 2001 at 09:11 UTC ( #55183=CUFP: print w/ replies, xml ) Need Help??

While fighting with today's CERT named advisory, I found myself upgrading to BIND9. During this madness, I realized I (and people before me) hadn't kept our DNS zone files to strict RFC compliance, and therefore BIND9 wouldn't load them (it requires strict compliance to the RFC.. I guess it's the
use strict
of the BIND world)

A zone file as I had it looked as thus:
domain.com.  IN  SOA  ns.domain.com.  root.domain.com
(
  200101261 ; serial
  10800 ; refresh
  3600 ; retry
  604800 ; expire
  86400 ) ; min ttl

In the RFC, the first line has to conclude with the open paren, and I figured while I was using perl to make these modifications, I'll make it look like so:
domain.com. IN SOA  ns.domain.com. root.domain.com (
  200101261 10800 3600 604800 86400 )
Enter perl and my gross regex code.. It's probably not the best, but it worked well for me:
#!/usr/bin/perl $/=""; while(<>) { $_ =~ s/([^(]*)\n\(\n/$1 \(\n/; # Move blankline ( to SOA lin +e $_ =~ s/\(\n\s*?(\d+)[^\n]*\n\s*?(\d+)[^\n]*\n\s*?(\d+)[^\n]*\ +n\s*?(\d+)[^\n]*\n\s*?(\d+)[^\n]*\n/\(\n\t\t$1 $2 $3 $4 $5 \)\n/; print $_; };
Run that with a perl -pi and pass it your DNS zones if they were setup like mine. Only messed up three zones out of 305. Not too bad. Maybe it'll save you some time if you too are dealing with BIND. =]

-marius

Comment on Fixing up DNS Zone Files
Download Code
Re: Fixing up DNS Zone Files
by Anonymous Monk on Feb 05, 2001 at 08:37 UTC
    Lucky you - I decided to only go as far as 8.2.2 => 8.2.3, and still found at least half a dozen different types of error that caused zones to be rejected. Mind, there are about 140,000 zones on our nameservers.

    The code I ended up with is way to ugly to post; come on Matthew, roll on with DNS::ZoneFile. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://55183]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-12-27 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls