# Add a third DNS and MX information



## bradwhitfield (Jan 30, 2012)

I work for a company who does web hosting for clients using FreeBSD 8. We have recently added a third offsite DNS for more fault tolerance. Any website that we have hosted since we added the new DNS has all three listed. Anything before currently has just the original two.

Basically, I was wondering if there is a way to automate the process of adding the new DNS and MX information to every site that we hosted before the new DNS server was added? Or am I stuck editing each sites' information one at a time?

If you need anymore information, please let me know.
Any reply is greatly appreciated.

Thanks!


----------



## gkontos (Jan 30, 2012)

The 3rd DNS server should be able to pick all your sites once they are added to the master.

Your main problem is that this DNS server has to be declared for every domain which is something that only a registrar can do and usually it requires end user intervention.


----------



## DutchDaemon (Jan 30, 2012)

If you have the 'raw' zone files at your disposal, using any scripting language should enable you to add MX and NS records using some grep/sed/awk magic, or perl.


----------



## bradwhitfield (Jan 30, 2012)

Thanks guys. I won't be able to look at it much till Wednesday but I appreciate the replies.


----------



## throAU (Jan 31, 2012)

I just went through something similar - updating a bunch of zone files, to get them all in a sane state and structured the same.  

As they're all hosted on the same network, they all had similar records.

I did it with sed, and make.

Basic theory - write a template file like:

ZONEFILE-TEMPLATE

```
$TTL 2d                 ; Zone default TTL 2 days
$ORIGIN #DOMAIN#.       ; BCM zonefile template v0.16
@               IN      SOA     ns1     hostmaster.yourdomain.com. (
                                #SOA#           ; serial number
                                30m                     ; Refresh
                                3m                      ; Update retry
                                7d                      ; Expiry
                                3h      )               ; Minimum

                IN      NS      #DNS1#
                IN      NS      #DNS2#
                IN      MX      10      your-common-mx-here.
                IN      A       #ARECORD#               ; DEFAULT BCM website IP
ns1             IN      A       #NS1#

.... etc....
```

(essentially, anything with #foo# will be replaced by definitions in the next file...)

Then, I made a file for substitutions for each domain, like:

IN.byrnecut.com.au

```
s/#SOA#/2011110301/g
s/#DOMAIN#/byrnecut.com.au/g
s/#WWW#/61.8.187.150/g
s/#ARECORD#/61.8.187.150/g
s/#DNS1#/ns1/g
s/#DNS2#/ns1.telstra.net./g


... etc ...
```

And then run this through sed, like:


```
cat ZONEFILE-TEMPLATE | sed -f INPUT/IN.byrnecut.com.au > byrnecut.com.au
```


As I have heaps of domains, I automated that with a Makefile, eg:

Makefile

```
byrnecut.com.au:        INPUT/IN.byrnecut.com.au ZONEFILE-TEMPLATE
        cat ZONEFILE-TEMPLATE | sed -f INPUT/IN.byrnecut.com.au > byrnecut.com.au

(copy/paste/modify above 2 lines for additional domains)
```


You will need to tweak to suit your environment, and be careful to run it all in a test directory first (and back up your zone files!!).... but that works for me.


Its a fair bit of work up front, but it means that for me adding new zones is very easy (create substitution file, add 2 lines to my Makefile, add zone to named.conf), and updating them all in one hit means changing the details in the template and running make (plus bumping the SOA, I should move that to the template file ).

It makes it a lot harder to screw up with typos... (conversely, a typo in my template screws all my domains simultaneously )


----------

