Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a standard high-availability setup at a co-location facility that we host client programs on. For some programs, we host the DNS, but I find that setting up multiple zones manually can be tedious and prone to error. Is there an easy way to setup a standard zone file template and some how run sed, awk, or some other program to process a set of variables from another file and merge them with the template to create a zone file?

I thought about using m4, but I'm not well versed and it only seems ideal for merging one template at a time.

Ideally, I'd like to take a standard zone file template and merge it with a list like so:


Is there a way to script this?

share|improve this question
up vote 3 down vote accepted

I think m4 would be overkill. My first instinct would be bash + sed, but if you have any familiarity with a higher-level language that might be easier. Off the top of my head, I would imagine something like this:

Data file:




for data in $(cat $DATAFILE)
    sed "{ s/DOMAIN/$dom/;
         }" $TEMPLATE > $

And your template zone file would have "DOMAIN" or "IPADDR" where appropriate.

This is completely untested and should be refined before use.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.