Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Fixing up DNS Zone Files

by marius (Hermit)
on Jan 30, 2001 at 09:11 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found