Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I have a webserver (running Ubuntu 12.04 server & Nginx) And I am setting up a number of websites on it.

I'm quite new to managing my own webserver, and I'm getting on pretty well except for when it comes to configuring the DNS.

I'd like to have the one server act as both the webserver and the DNS server (unless somebody can convince me otherwise..)

I've read through a couple BIND9 guides, but just don't understand why it has to be so complicated!

I would like one script, which I can run, something like: which would create the zones and entries for 'mydomain' and set the current server as the host, and authorative server.

Ideally I would like my workflow for a new domain simply to be:

  • Register the domain at a registrar
  • At the registrar, set my DNS to be my server
  • On my server, run 1 script which sets up the relevant DNS entries
  • On my server, run 1 script which sets up the relevant webserver configs (I already have this)

So, Can you add a DNS entry with a simple bash script?

Thanks, Dean.

share|improve this question
Nearly everything in Unix/Linux can be scripted because that's the way it's meant to be. As you're a beginner then you should start with some documentation and faq. – Iain Jul 12 '12 at 6:12
up vote 3 down vote accepted

add to /etc/bind/named.conf:

include "/etc/bind/domain-enabled.conf";

make dir:

# mkdir /etc/bind/domain-enabled/


cat <<EOF >>/etc/bind/domain-enabled.conf
zone "$1" {
        type master;
        file "/etc/bind/domain-enabled/$1.db";
cat <<EOF >/etc/bind/domain-enabled/$1.db
\$TTL   604800
@       IN      SOA     ns1.$1. root.localhost. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
@       IN      NS      ns1.$1.
@       IN      A       $2
ns1     IN      A       $2
rndc reload


share|improve this answer
I ended up using a modified version of this script in my solution; there were a few other steps involved so I'll link it here in the comments once I've published it! Thanks! – Dean Rather Jul 19 '12 at 23:38

Yes, I've automated DNS management with shell scripts several times, for different infrastructures at different places of employment.

As to your other pseudo-question, "why it has to be so complicated", that's because DNS isn't a trivial thing in the general case, and BIND attempts to handle all the complicated corner cases. This means that the simple things aren't (quite) as simple as they might otherwise be, however it's nice to know that no matter how hairy things get, you'll be able to handle it.

share|improve this answer

Check out h2n. It's referenced in the BIND books by O'Reilly.

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.