Saturday, July 9, 2011

DNS on Linux?

I'm the sort of person who likes to make things work without having to read a few text books. So, when I needed to run my own web server I feared the setup of a name server. I first searched Google for "setup dns on linux" or "dns setup ubuntu" but by the time I just about had it working I was searching for "bind9 linux". It was tough but it's working, I don't entirely know why but here's how a total noob pulled it off:

Environment:
Ubuntu 11, Apache 2, Bind 9
Building IP: 12.0.0.1
System IP: 192.168.0.2
Domain name: example.com (at godaddy.com)

The steps which succeeded:
1. Install apache (sudo apt-get install apache2)

2. Install bind9 (sudo apt-get install bind9)

3. Open an account at buddyns.com (domain = example.com // server = 12.0.0.1)

4. Register your name server at godaddy.com under "Add host summary", add ns1.example.com.

5. Edit your name servers at godaddy.com for example.com (ns1.example.com, b.ns.buddyns.com, c.ns.buddyns.com)

6. Edit resolv.conf (sudo gedit /etc/resolv.conf) to look like:

nameserver 127.0.0.1
nameserver b.ns.buddyns.com
nameserver c.ns.buddyns.com

7. Edit zones (sudo gedit /etc/bind/named.conf.local) to look like:

zone "example.com" {
type master;
file "/etc/bind/db.example.com";
};
zone "ns1.example.com" {
type master;
file "/etc/bind/db.example.com";
};



8. Edit zone file (sudo gedit /etc/bind/db.example.com) to look like:

$TTL 604800
@ IN SOA ns1.example.com. root.localhost. (
      1 ; Serial
604800 ; Refresh
 86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.example.com.
@ IN A 67.185.67.129
ns IN A 67.185.67.129
$TTL 604800
@ IN SOA example.com. root.localhost. (
      2 ; Serial
604800 ; Refresh
 86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS example.com.
@ IN A 67.185.67.129
ns IN A 67.185.67.129


9. Edit bind options (sudo gedit /etc/bind/named.conf.options) to look like:

options {
directory "/var/cache/bind";
forwarders {
173.244.206.26; //buddyns
82.130.104.115; //buddyns
};
allow-transfer {
173.244.206.26; //buddyns
74.117.59.111; //buddyns
};
recursion yes;
allow-recursion { 127.0.0.1; };
auth-nxdomain no;    # conform to RFC1035
listen-on-v6 { any; };
};

10. Edit apache virtual hosts (sudo gedit /etc/apache2/httpd.conf) to look like:

NameVirtualHost *

    <VirtualHost *>
    ServerName example.com
    DocumentRoot /var/www/example.com
    </VirtualHost>

    <VirtualHost *>
    ServerName www.example.com
    DocumentRoot /var/www/example.com
    </VirtualHost>
    <VirtualHost *>
    ServerName ns1.example.com
    DocumentRoot /var/www/example.com
    </VirtualHost>

11. Restart apache (sudo /etc/init.d/apache2 restart)

12. Restart bind9 (sudo /etc/init.d/bind9 restart)

13. Try it out.

I hope that's right. I did so many things to get this to work that I likely forgot something but I think these attributes will at least help get you going in the right direction. Enjoy.

1 comment:

  1. Hello from BuddyNS :)

    We are glad that BuddyNS helped you end the setup trouble, and thanks for providing a start-to-finish recipe!

    One tip:

    The NS settings at the registry (GoDaddy) and master (/etc/bind/db.example.com) should always match. So if you say

    "5. Edit your name servers at godaddy.com for example.com (ns1.example.com, b.ns.buddyns.com, c.ns.buddyns.com)"

    Then you should say in #8:
    "8. Edit zone file (sudo gedit /etc/bind/db.example.com) to look like:
    @ IN NS ns1.example.com.
    @ IN NS b.ns.buddyns.com.
    @ IN NS c.ns.buddyns.com.
    "

    You can also use all of the 4 nameservers we provide: "b, c, d, e".ns.buddyns.com for improved performance and uptime.

    Would you be nice and change your "Open an account at buddyns.com" into an actual link"?

    cheers!
    The BuddyNS team
    http://www.buddyns.com

    ReplyDelete