Showing posts with label dns server. Show all posts
Showing posts with label dns server. Show all posts

Ubuntu dns server configuration

Ubuntu dns server configuration involves many files. I would like to remind you again, please make a backup for every files before you begin editing. Example below:




luzar@ubuntu:/etc/bind$ sudo cp named.conf.local named.conf.local.bak
luzar@ubuntu:/etc/bind$ sudo cp named.conf.options named.conf.options.bak



The first file we are going to edit is the named.conf.local file. Use your favorite editor to open named.conf.local file.




luzar@ubuntu:/etc/bind$ sudo vim /etc/bind/named.conf.local



Type the code below. Replace example.com. with your domain name.





zone "example.com" in {
allow-transfer { any; };
file "/etc/bind/db.example.com.";
type master;
};


// Set up reversed name resolution
zone "1.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192";
};



Example of /etc/bind/db.example.com configuration.





;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA ubuntu.example.com. root.example.com. (
2008112202 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
86400 ) ; Negative Cache TTL
;

example.com IN MX mail.example.com.
@ IN NS ubuntu.example.com.
@ IN A 192.168.1.3
ubuntu IN A 192.168.1.3
web IN CNAME ubuntu.example.com.



Example of /etc/bind/db.192 configuration.





;
; Reverse lookup DNS Zone file
;
$TTL 604800
@ IN SOA ubuntu.example.com. root.example.com. (
2008112302 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
86400 ) ; Negative Cache TTL
@ IN NS ubuntu.
3 IN CNAME ubuntu.example.com.



You have to set the ISP dns server ip address. Put it in /etc/bind/named.conf.options forwarders:





// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.


forwarders {
123.123.0.123;
123.123.1.1;
};



Example of /etc/resolv.conf configuration:

search example.comnameserver 192.168.1.3

Example of /etc/hosts configuration:





127.0.0.1 localhost
192.168.1.3 ubuntu.example.com ubuntu

# The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopbackfe00
::0 ip6-localnetff00
::0 ip6-mcastprefixff02
::1 ip6-allnodesff02
::2 ip6-allroutersff02
::3 ip6-allhosts



Restart bind9 service with the command below:




luzar@ubuntu:~$ sudo /etc/init.d/bind9 restart
* Stopping domain name service... bind [ OK ]
* Starting domain name service... bind [ OK ]

luzar@ubuntu:~$ tail /var/log/messages



Testing dns with dig domain name command:




luzar@ubuntu:/etc/bind$ dig example.com

; <<>> DiG 9.4.2-P2 <<>> example.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34700
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1,
ADDITIONAL: 1

;; QUESTION SECTION:;example.com. IN A


;; ANSWER SECTION:
example.com. 604800 IN A 192.168.1.3


;; AUTHORITY SECTION:
example.com. 604800 IN NS ubuntu.example.com.


;; ADDITIONAL SECTION:
ubuntu.example.com. 604800 IN A 192.168.1.3


;; Query time: 0 msec
;; SERVER: 192.168.1.3#53(192.168.1.3)
;; WHEN: Sun Nov 23 04:23:18 2008
;; MSG SIZE rcvd: 82


luzar@ubuntu:/etc/bind$



Testing with dig ip address:




luzar@ubuntu:/etc/bind$ dig -x 192.168.1.3


; <<>> DiG 9.4.2-P2 <<>> -x 192.168.1.3
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35746
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1,
ADDITIONAL: 0


;; QUESTION SECTION:
;3.1.168.192.in-addr.arpa. IN PTR


;; ANSWER SECTION:
3.1.168.192.in-addr.arpa. 604800 IN CNAME ubuntu.example.com.


;; AUTHORITY SECTION:
example.com. 86400 IN SOA ubuntu.example.com.
root.example.com. 2008112202 604800 86400 2419200 86400


;; Query time: 0 msec
;; SERVER: 192.168.1.3#53(192.168.1.3)
;; WHEN: Sun Nov 23 04:32:09 2008
;; MSG SIZE rcvd: 115
luzar@ubuntu:/etc/bind$



If you have an error during configuration, please check error logs in:





  • /var/log/daemon.log.

  • /var/log/messages.




Here is an example of /var/log/daemon.log:




luzar@ubuntu:/etc/bind$ tail /var/log/daemon.log

Nov 24 10:23:05 ubuntu named[4554]: zone 28.172.in-addr.arpa/IN:
loaded serial 1
Nov 24 10:23:05 ubuntu named[4554]: zone 29.172.in-addr.arpa/IN:
loaded serial 1
Nov 24 10:23:05 ubuntu named[4554]: zone 30.172.in-addr.arpa/IN:
loaded serial 1
Nov 24 10:23:05 ubuntu named[4554]: zone 31.172.in-addr.arpa/IN:
loaded serial 1
Nov 24 10:23:05 ubuntu named[4554]: zone 168.192.in-addr.arpa/IN:
loaded serial 1
Nov 24 10:23:05 ubuntu named[4554]: zone 1.168.192.in-addr.arpa/IN:
loaded serial 2008112302
Nov 24 10:23:05 ubuntu named[4554]: zone 255.in-addr.arpa/IN:
loaded serial 1
Nov 24 10:23:05 ubuntu named[4554]: zone example.com/IN:
loaded serial 2008112202
Nov 24 10:23:05 ubuntu named[4554]: zone localhost/IN:
loaded serial 2
Nov 24 10:23:05 ubuntu named[4554]: running

Ubuntu named.conf

Ubuntu named.conf file is the master configuration file for DNS server. Its pronounced name-dee for name daemon, which is the dns service. It's location is in /etc/bind/named.conf. You can find named.conf file only after you install the bind9 software package.




Here is an example of a default Ubuntu /etc/bind/named.conf configuration file:





// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in
// include "/etc/bind/named.conf.local

include "/etc/bind/named.conf.options";
// prime the server with knowledge of the root servers

zone "." {
type hint;
file "/etc/bind/db.root";
};

// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912

zone "localhost" {
type master;
file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
type master;
file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
type master;
file "/etc/bind/db.255";
};

include "/etc/bind/named.conf.local";



The named.conf is a very important file. Normally, you don't have to edit this file during dns configuration in Ubuntu. However, maybe you are going to open and view this file a few times to study it's configuration. It's a good idea to copy and make a backup of this file.




luzar@ubuntu:/etc/bind$ sudo cp named.conf named.conf.bak
[sudo] password for luzar:
luzar@ubuntu:/etc/bind$



As you can see, there are specific files in each zone in the named.conf configuration file above. Those are the database files for localhost and default dns configuration. We don't need to edit those files. You only need to edit two files mention at the top of named.conf which is /etc/bind/named.conf.local and /etc/bind/named.conf.options.

Ubuntu dns files

DNS is domain name system. In Ubuntu, DNS package is included in bind9 software package. The dns server is called named. Basically what dns do, it translates name to ip address. It also translates ip address to name, which is called reverse dns.




Setting up dns involves several other files in Ubuntu system, the directly involved bind9 configuration files package and related files not in bind package. Here are all files needed to set up dns server, in bind package and not in bind package.

DNS configuration files in bind package:




luzar@ubuntu:~$ cd /etc/bind/
luzar@ubuntu:/etc/bind$ ls -l
total 44-rw-r--r-- 1 root root 237 2011-05-09 15:42 db.0
-rw-r--r-- 1 root root 271 2011-05-09 15:42 db.127
-rw-r--r-- 1 root root 237 2011-05-09 15:42 db.255
-rw-r--r-- 1 root root 353 2011-05-09 15:42 db.empty
-rw-r--r-- 1 root root 270 2011-05-09 15:42 db.local
-rw-r--r-- 1 root root 2878 2011-05-09 15:42 db.root
-rw-r--r-- 1 root bind 907 2011-05-09 15:42 named.conf
-rw-r--r-- 1 root bind 165 2011-05-09 15:42 named.conf.local
-rw-r--r-- 1 root bind 695 2011-05-09 15:42 named.conf.options
-rw-r----- 1 bind bind 77 2011-05-20 10:56 rndc.key
-rw-r--r-- 1 root root 1317 2011-05-09 15:42 zones.rfc1918
luzar@ubuntu:/etc/bind$



Related files not in bind package:



  • /etc/resolv.conf
  • /etc/hosts

  • /etc/nsswitch.conf




Here are screenshots of the files:




/etc/named.conf




/etc/named.conf is the main dns server configuration file. Here is a default content screenshot:







/etc/resolv.conf




/etc/resolv.conf is dns resolver file. Here is a default content screenshot:







/etc/bind/named.conf.local




/etc/bind/named.conf.local is a zone configuration file for dns setup. Here is a default content screenshot:







/etc/bind/named.conf.options




/etc/bind/named.conf.options file contains generic options for bind bind name server. Here is a default content screenshot:







Bind databases files




/etc/bind/db.root







/etc/bind/db.local







/etc/bind/db.0







/etc/bind/db.255







/etc/bind/db.127







/etc/bind/db.empty




Ubuntu install dns server

Ubuntu uses named as its DNS or Internet domain name system server. Named is part of BIND 9 distribution from ISC. So, to install Ubuntu dns server, you must install bind software package. Luckily, there is no hassle installing software package in Ubuntu. There are more than one great package management system in Ubuntu that you can use.




Before we begin the bind9 installation, we better run apt-get update to resynchronize the package index files from the sources. So here we go:




luzar@ubuntu:~$ sudo apt-get update
[sudo] password for luzar:
Get:1 http://security.ubuntu.com hardy-security Release.gpg [189B]
Ign http://security.ubuntu.com hardy-security/main Translation-en_US
Hit http://us.archive.ubuntu.com hardy Release.gpg.........
Fetched 964kB in 13s (69.6kB/s)Reading package lists...
Done



After running the update, we have to run the apt-get upgrade command to update software in our system to the latest update. See an example below:




luzar@ubuntu:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
.........
Setting up mysql-server (5.0.51a-3ubuntu5.4) ...
Setting up libxml2 (2.6.31.dfsg-2ubuntu1.3) ...
Processing triggers for libc6 ...
ldconfig deferred processing now taking place



After the upgrade is finished, we can run apt-get install to install bind9 software package. Here is how the real installation go:




luzar@ubuntu:~$ sudo apt-get install bind9
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libbind9-30 libdns35 libisc35 libisccc30 libisccfg30
Suggested packages: resolvconf
The following NEW packages will be installed: libdns35 libisc35
The following packages will be upgraded:
bind9 libbind9-30 libisccc30 libisccfg30
4 upgraded, 2 newly installed, 0 to remove and 5 not upgraded.
Need to get 978kB of archives.
After this operation, 1651kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://us.archive.ubuntu.com hardy-updates/main libisc35
1:9.4.2.dfsg.P2-2 [127kB]
Get:2 http://us.archive.ubuntu.com hardy-updates/main libdns35
1:9.4.2.dfsg.P2-2 [494kB]
Get:3 http://us.archive.ubuntu.com hardy-updates/main bind9
1:9.4.2.dfsg.P2-2 [268kB]
Get:4 http://us.archive.ubuntu.com hardy-updates/main libisccc30
1:9.4.2.dfsg.P2-2 [23.1kB]
Get:5 http://us.archive.ubuntu.com hardy-updates/main libisccfg30
1:9.4.2.dfsg.P2-2 [38.5kB]
Get:6 http://us.archive.ubuntu.com hardy-updates/main libbind9-30
1:9.4.2.dfsg.P2-2 [27.5kB]
Fetched 978kB in 15s (63.8kB/s)
Selecting previously deselected package libisc35.
(Reading database ...
18940 files and directories currently installed.)
Unpacking libisc35 (from .../libisc35_1%3a9.4.2.dfsg.P2-2_i386.deb)
...
Selecting previously deselected package libdns35.
Unpacking libdns35 (from .../libdns35_1%3a9.4.2.dfsg.P2-2_i386.deb)
...
Preparing to replace bind9 1:9.4.2-10
(using .../bind9_1%3a9.4.2.dfsg.P2-2_i386.deb
) ...
* Stopping domain name service... bind [ OK ]
Unpacking replacement bind9 ...
Preparing to replace libisccc30 1:9.4.2-10
(using .../libisccc30_1%3a9.4.2.dfsg.P2-2_i386.deb)
...
Unpacking replacement libisccc30 ...
Preparing to replace libisccfg30 1:9.4.2-10
(using .../libisccfg30_1%3a9.4.2.dfsg.P2-2_i386.deb)
...
Unpacking replacement libisccfg30
...
Preparing to replace libbind9-30 1:9.4.2-10
(using .../libbind9-30_1%3a9.4.2.dfsg.P2-2_i386.deb)
...
Unpacking replacement libbind9-30
...
Setting up libisc35 (1:9.4.2.dfsg.P2-2)
...
Setting up libdns35 (1:9.4.2.dfsg.P2-2)
...
Setting up libisccc30 (1:9.4.2.dfsg.P2-2)
...
Setting up libisccfg30 (1:9.4.2.dfsg.P2-2
) ...
Setting up libbind9-30 (1:9.4.2.dfsg.P2-2
) ...
Setting up bind9 (1:9.4.2.dfsg.P2-2
) ...
Installing new version of config file /etc/apparmor.d/usr.sbin.named
...
Reloading AppArmor profiles : done.
* Starting domain name service... bind [ OK ]
Processing triggers for libc6 ...
ldconfig deferred processing now taking place
luzar@ubuntu:~$



We have successfully installed bind9 package. Now, let's see what version we got:




luzar@ubuntu:~$ named -vBIND 9.4.2-P2
luzar@ubuntu:~$



So that's it. We already have bind9 package installed in our system. What to do next is to configure our dns server.