DNS server

From WickyWiki
Revision as of 07:26, 5 July 2013 by Admin (talk | contribs) (24 revisions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Install a DNS server and configure a local DNS record.


Install

sudo apt-get install bind9

Configure zone

Add domain 'mydomain.com':

sudo gedit /etc/bind/named.conf.local
zone "mydomain.com" {
   type master;
   file "/etc/bind/db.mydomain.com";
};

Configure this file to use the provider's DNS server:

sudo gedit /etc/bind/named.conf.options
...
forwarders {
   88.159.1.200;
   88.159.1.201;
};
...

Define the zones, use '/etc/bind/db.local' as a template:

  • ns = DNS Server name
  • mydomain.com = domain name
  • increment the Serial Number with each change
sudo cp /etc/bind/db.local /etc/bind/db.mydomain.com
sudo gedit /etc/bind/db.mydomain.com
$TTL    604800                          ; time to live
@       IN      SOA     ns.mydomain.com. admin-email.mydomain.com. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.mydomain.com.
@       IN      A       192.168.1.10
@       IN      AAAA    ::1
ns      IN      A       192.168.1.10

Configure reverse zone

A Reverse zone allows DNS to resolve an address to a name. Note the reversed IP address sequence '1.168.192' with the last octet missing.

sudo gedit /etc/bind/named.conf.local

Add the following:

...
zone "1.168.192.in-addr.arpa" {
   type master;
   file "/etc/bind/rv.192";
};

Create the reverse zone file, use '/etc/bind/db.127' as a template:

sudo cp /etc/bind/db.127 /etc/bind/rv.192
sudo gedit /etc/bind/rv.192
$TTL	604800          ; time to live
@	IN	SOA	ns.mydomain.com. root.mydomain.com. (
			      1		; Serial
			 604800		; Refresh
			  86400		; Retry
			2419200		; Expire
			 604800 )	; Negative Cache TTL
;
@	IN	NS	ns.
10	IN	PTR	ns.mydomain.com.

Configure nameserver

Modify the resolv.conf to point to our DNS server, also see 'Configure fixed IP address' otherwise this file will be overwritten by the networkmanager:

sudo gedit /etc/resolv.conf
search mydomain.com.
nameserver 192.168.1.10

Hostname

Configure the hostname:

sudo gedit /etc/hostname
mydomain.com
sudo gedit /etc/hosts
127.0.1.1   mydomain.com   mydomain
hostname --fqdn

Restart and test

Restart Bind:

sudo /etc/init.d/bind9 restart

Test our new domain and DNS entries:

dig mydomain.com @dnsserver
dig mydomain.com
...
;; ANSWER SECTION:
mydomain.com.		604800	IN	A	192.168.1.10
...

Router settings

If you want your local network to use your DNS you need to configure your router to hand out your server as primary DNS. Make sure you can configure a secondary DNS and that it is available. When your server is down the secondary DNS will be used.