Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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: configure-dns.sh mydomain.com 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

3 Answers 3

up vote 2 down vote accepted

add to /etc/bind/named.conf:

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

make dir:

# mkdir /etc/bind/domain-enabled/

scripts:

cat <<EOF >>/etc/bind/domain-enabled.conf
zone "$1" {
        type master;
        file "/etc/bind/domain-enabled/$1.db";
};
EOF
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
EOF
rndc reload

run:

add-domain examle.com 127.0.0.1
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.

http://my.safaribooksonline.com/book/networking/dns/0789722739/the-dns-tool-chest/ch07lev1sec2

share|improve this answer

Your Answer

 
discard

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.