{"id":898,"date":"2018-04-10T15:08:41","date_gmt":"2018-04-10T12:08:41","guid":{"rendered":"https:\/\/helia.ee\/koolitus\/?page_id=898"},"modified":"2018-04-10T15:08:41","modified_gmt":"2018-04-10T12:08:41","slug":"configure-dns-server-debian-9-ubuntu-16-04","status":"publish","type":"page","link":"https:\/\/helia.ee\/koolitus\/?page_id=898","title":{"rendered":"Configure DNS Server On Debian 9 \/ Ubuntu 16.04"},"content":{"rendered":"<p><strong><a href=\"https:\/\/www.itzgeek.com\/tag\/dns\">Domain Name System<\/a><\/strong> (in short, DNS) is an internet service that is used to resolve Domain Name to IP Address and vice versa.<\/p>\n<p>BIND (Berkeley Internet Name Domain) provides the functionality of name to ip conversion.<\/p>\n<p>This post will help you configure <strong><a href=\"https:\/\/www.itzgeek.com\/tag\/dns\">DNS server<\/a><\/strong> on <strong><a href=\"https:\/\/www.itzgeek.com\/tag\/debian-9\">Debian 9<\/a><\/strong> \/ <strong><a href=\"https:\/\/www.itzgeek.com\/tag\/ubuntu-16.04\">Ubuntu 16.04<\/a><\/strong>.<\/p>\n<h2>Environment<\/h2>\n<p><strong>Domain: itzgeek.local<\/strong><\/p>\n<p><strong>Primary DNS server:\u00a0 (It is the master server, and DNS records are created here.)<br \/>\n<\/strong><\/p>\n<p>Server Name: ns1.itzgeek.local<\/p>\n<p>IP Address: 192.168.1.10<\/p>\n<p><strong>Secondary DNS server: (It is the slave server, gets DNS records from the Master server. It acts as a backup DNS server for the primary server if the primary server goes down.)<br \/>\n<\/strong><\/p>\n<p>Server Name: ns2.itzgeek.local<\/p>\n<p>IP Address: 192.168.1.20<\/p>\n<p><strong>In this post, we set up only the primary DNS server. In case if you are planning to implement secondary server then take a look at <a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/configure-slave-dns-server-on-debian-9-ubuntu-16-04.html\">configuring slave DNS server on Debian 9 \/ Ubuntu 16.04<\/a>.<\/strong><\/p>\n<h2>Prerequisites<\/h2>\n<p>Switch to the root user.<\/p>\n<pre>su -<\/pre>\n<p>OR<\/p>\n<pre>sudo su -<\/pre>\n<p>Update the repository index.<\/p>\n<pre>apt-get update<\/pre>\n<p><strong>Make sure both primary and secondary server has a static IP address.<\/strong><\/p>\n<div class=\"bsac bsac-clearfix bsac-post-inline bsac-float-center bsac-align-center bsac-column-1\">\n<div id=\"bsac-25694-2076070239\" class=\"bsac-container bsac-type-code \" data-adid=\"25694\" data-type=\"code\"><\/div>\n<\/div>\n<p><strong>READ<\/strong>: <strong><a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/how-to-configure-static-ip-address-in-ubuntu-debian.html\" rel=\"noopener\">How to configure static ip address in Debian \/ Ubuntu \/ LinuxMint<\/a><\/strong><\/p>\n<h2>Install DNS Server<\/h2>\n<p><strong>The package name of DNS in Debian \/ Ubuntu is bind9 and is available in the base repository<\/strong>. You can use apt command to install bind9 package.<\/p>\n<pre>apt-get install -y bind9 bind9utils bind9-doc dnsutils<\/pre>\n<h2>Configure DNS Server<\/h2>\n<p><strong>\/etc\/bind\/ is the configuration directory of bind9<\/strong>, holds configuration files and zone lookup files. <strong>Global configuration file is \/etc\/bind\/named.conf.<\/strong><\/p>\n<h3>Create Zone\u2019s<\/h3>\n<p>Let us begin with creating forward zone for your domain.<\/p>\n<p><strong>You should not use the global configuration file for local DNS zone rather you can use \/etc\/bind\/named.conf.local file.<\/strong><\/p>\n<pre>nano \/etc\/bind\/named.conf.local<\/pre>\n<p><strong>Forward Zone:<\/strong><\/p>\n<p>The following is the forward zone entry for the itzgeek.local domain in the named.conf.local file.<\/p>\n<pre>zone \"itzgeek.local\" IN { <strong>\/\/Domain name<\/strong>\r\n     type master; <strong>\/\/Primary DNS<\/strong>\r\n     file \"\/etc\/bind\/fwd.itzgeek.local.db\"; <strong>\/\/Forward lookup file<\/strong>\r\n     allow-update { none; }; <strong>\/\/ Since this is the primary DNS, it should be none.<\/strong>\r\n};\r\n<\/pre>\n<p><strong>Reverse Zone:<\/strong><\/p>\n<p>The following is for the reverse zone in the named.conf.local file.<\/p>\n<pre>zone \"1.168.192.in-addr.arpa\" IN { <strong>\/\/Reverse lookup name, should match your network in reverse order<\/strong>\r\n     type master; <strong>\/\/ Primary DNS<\/strong>\r\n     file \"\/etc\/bind\/rev.itzgeek.local.db\"; <strong>\/\/Reverse lookup file<\/strong>\r\n     allow-update { none; }; <strong>\/\/Since this is the primary DNS, it should be none.<\/strong>\r\n};\r\n<\/pre>\n<h3>Create Zone lookup file<\/h3>\n<p>Once zones are created, you can go ahead and create zone data files for the forward zone and reverse zone.<\/p>\n<p><strong>Forward Zone lookup file:<\/strong><\/p>\n<p>Copy the sample entries to zone file called fwd.itzgeek.local.db for forward zone under \/etc\/bind directory.<\/p>\n<p>Record types in zone file,<\/p>\n<p><strong>SOA \u2013 Start of Authority<\/strong><br \/>\n<strong>NS \u2013 Name Server<\/strong><br \/>\n<strong>A \u2013 A record<\/strong><br \/>\n<strong>MX \u2013 Mail for Exchange<\/strong><br \/>\n<strong>CN \u2013 Canonical Name<\/strong><\/p>\n<p><strong>Domain names should end with a dot (.).<\/strong><\/p>\n<div class=\"bsac bsac-clearfix bsac-post-inline bsac-float-center bsac-align-center bsac-column-1\">\n<div id=\"bsac-25694-1956718175\" class=\"bsac-container bsac-type-code \" data-adid=\"25694\" data-type=\"code\"><\/div>\n<\/div>\n<pre>cp \/etc\/bind\/db.local \/etc\/bind\/fwd.itzgeek.local.db<\/pre>\n<p>Edit the zone.<\/p>\n<pre>nano \/etc\/bind\/fwd.itzgeek.local.db<\/pre>\n<p>Update the content shown like below. <strong>Whenever you change any records in the lookup file, make sure you update the serial number to some random number, higher than current.<\/strong><\/p>\n<pre>;\r\n; BIND data file for local loopback interface\r\n;\r\n$TTL    604800\r\n@       IN      SOA     ns1.itzgeek.local. root.itzgeek.local. (\r\n                            <strong> 20         ; Serial<\/strong>\r\n                         604800         ; Refresh\r\n                          86400         ; Retry\r\n                        2419200         ; Expire\r\n                         604800 )       ; Negative Cache TTL\r\n;\r\n;@      IN      NS      localhost.\r\n;@      IN      A       127.0.0.1\r\n;@      IN      AAAA    ::1\r\n\r\n<strong>;Name Server Information<\/strong>\r\n       IN      NS      ns1.itzgeek.local.\r\n       IN      NS      ns2.itzgeek.local.\r\n<strong>;IP address of Name Server<\/strong>\r\nns1     IN      A       192.168.1.10\r\nns2     IN      A       192.168.1.20\r\n<strong>\r\n;Mail Exchanger<\/strong>\r\nitzgeek.local.   IN     MX   10   mail.itzgeek.local.\r\n\r\n<strong>;A - Record HostName To Ip Address<\/strong>\r\nwww     IN       A      192.168.1.100\r\nmail    IN       A      192.168.1.150\r\n@       IN       A      192.168.1.200\r\n<strong>;CNAME record<\/strong>\r\nftp     IN      CNAME   www.itgeek.local.\r\n<\/pre>\n<p><strong>Reverse Zone lookup file:<\/strong><\/p>\n<p>Copy the sample entries to zone file called rev.itzgeek.local.db for reverse zone under \/etc\/bind directory and create reverse pointers for the above forward zone records.<\/p>\n<p><strong>PTR \u2013 Pointer<\/strong><br \/>\n<strong>SOA \u2013 Start of Authority<\/strong><\/p>\n<pre>cp \/etc\/bind\/db.127 \/etc\/bind\/rev.itzgeek.local.db<\/pre>\n<p>Edit the reverse zone file.<\/p>\n<pre>nano \/etc\/bind\/rev.itzgeek.local.db<\/pre>\n<p>Update the content shown like below. <strong>Whenever you change any records in the lookup file, make sure you update the serial number to some random number, higher than current.<\/strong><\/p>\n<pre>;\r\n; BIND reverse data file for local loopback interface\r\n;\r\n$TTL    604800\r\n@       IN      SOA     itzgeek.local. root.itzgeek.local. (\r\n                            <strong> 20         ; Serial<\/strong>\r\n                         604800         ; Refresh\r\n                          86400         ; Retry\r\n                        2419200         ; Expire\r\n                         604800 )       ; Negative Cache TTL\r\n;\r\n;@      IN      NS      localhost.\r\n;1.0.0  IN      PTR     localhost.\r\n\r\n<strong>;Name Server Information<\/strong>\r\n       IN      NS     ns1.itzgeek.local.\r\n       IN      NS     ns2.itzgeek.local.\r\n<strong>;Reverse lookup for Name Server<\/strong>\r\n10      IN      PTR    ns1.itzgeek.local.\r\n20      IN      PTR    ns2.itzgeek.local.\r\n<strong>;PTR Record IP address to HostName<\/strong>\r\n100     IN      PTR    www.itzgeek.local.\r\n150     IN      PTR    mail.itzgeek.local.\r\n200     IN      PTR    itzgeek.local.\r\n<\/pre>\n<h3>Check BIND Configuration Syntax<\/h3>\n<p>Use <strong>named-checkconf<\/strong> command to check the syntax of named.conf* files for any errors.<\/p>\n<pre>named-checkconf<\/pre>\n<p><strong>Command will return to the shell if there are no errors.<\/strong><\/p>\n<p>Also, you can use<strong> named-checkzone <\/strong>to check the syntax errors in zone files.<\/p>\n<p>For foward zone:<\/p>\n<pre>named-checkzone itzgeek.local \/etc\/bind\/fwd.itzgeek.local.db<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre>zone itzgeek.local\/IN: loaded serial 20\r\nOK<\/pre>\n<p>For reverse zone:<\/p>\n<pre>named-checkzone 1.168.192.in-addr.arpa \/etc\/bind\/rev.itzgeek.local.db<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre>zone 1.168.192.in-addr.arpa\/IN: loaded serial 20\r\nOK<\/pre>\n<p>Restart bind service.<\/p>\n<div class=\"bsac bsac-clearfix bsac-post-inline bsac-float-center bsac-align-center bsac-column-1\">\n<div id=\"bsac-25694-1019042018\" class=\"bsac-container bsac-type-code \" data-adid=\"25694\" data-type=\"code\"><\/div>\n<\/div>\n<pre>systemctl restart bind9<\/pre>\n<p>Enable it on system startup.<\/p>\n<pre>systemctl enable bind9<\/pre>\n<p>Check the status of bind9 service.<\/p>\n<pre>systemctl status bind9<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre><strong>\u25cf<\/strong> bind9.service - BIND Domain Name Server\r\n   Loaded: loaded (\/lib\/systemd\/system\/bind9.service; enabled; vendor preset: enabled)\r\n   Active:<strong> active (running)<\/strong> since Mon 2017-10-09 13:31:54 EDT; 1min 51s ago\r\n     Docs: man:named(8)\r\n Main PID: 778 (named)\r\n    Tasks: 4 (limit: 4915)\r\n   CGroup: \/system.slice\/bind9.service\r\n           \u2514\u2500778 \/usr\/sbin\/named -f -u bind\r\n\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: managed-keys-zone: loaded serial 4\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: zone 0.in-addr.arpa\/IN: loaded serial 1\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: zone 127.in-addr.arpa\/IN: loaded serial 1\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: zone localhost\/IN: loaded serial 2\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: zone 1.168.192.in-addr.arpa\/IN: loaded serial 20\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: zone itzgeek.local\/IN: loaded serial 20\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: zone 255.in-addr.arpa\/IN: loaded serial 1\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: all zones loaded\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: running\r\nOct 09 13:31:55 ns1.itzgeek.local named[778]: zone 1.168.192.in-addr.arpa\/IN: sending notifies (serial 20)\r\n<\/pre>\n<h2>Verify DNS<\/h2>\n<p>Go to any client machine and add our new DNS server IP Address in \/etc\/resolv.conf file.<\/p>\n<pre>nano \/etc\/resolv.conf<\/pre>\n<p>Make an entry like below.<\/p>\n<pre>nameserver 192.168.1.10<\/pre>\n<p><strong>OR<\/strong><\/p>\n<p>Follow the below tutorial to add DNS server IP in Ubuntu \/ Debian.<\/p>\n<p><strong>READ<\/strong>: <strong><a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/how-to-configure-static-ip-address-in-ubuntu-debian.html\" rel=\"noopener\">How to add DNS IP address in Debian \/ Ubuntu \/ LinuxMint<\/a><\/strong><\/p>\n<p><strong>You can either use nslookup or dig command to verify the DNS server<\/strong>.<\/p>\n<p>Use the dig command to verify the forward lookup.<\/p>\n<pre>dig www.itzgeek.local<\/pre>\n<p><strong>If you get command not found, install bind-utils package.<\/strong><\/p>\n<p><strong>Output:<\/strong><\/p>\n<pre>; &lt;&lt;&gt;&gt; DiG 9.10.3-P4-Debian &lt;&lt;&gt;&gt; www.itzgeek.local @192.168.1.10\r\n;; global options: +cmd\r\n;; Got answer:\r\n;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 13117\r\n;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2\r\n\r\n;; OPT PSEUDOSECTION:\r\n; EDNS: version: 0, flags:; udp: 4096\r\n;; QUESTION SECTION:\r\n;www.itzgeek.local.             IN      A\r\n\r\n;; ANSWER SECTION:\r\n<strong>www.itzgeek.local.      604800  IN      A       192.168.1.100<\/strong>\r\n\r\n;; AUTHORITY SECTION:\r\nitzgeek.local.          604800  IN      NS      ns1.itzgeek.local.\r\n\r\n;; ADDITIONAL SECTION:\r\nns1.itzgeek.local.      604800  IN      A       192.168.1.10\r\n\r\n;; Query time: 0 msec\r\n;; SERVER: 192.168.1.10#53(192.168.1.10)\r\n;; WHEN: Mon Oct 09 13:14:22 EDT 2017\r\n;; MSG SIZE  rcvd: 96\r\n<\/pre>\n<p><strong>The DNS server\u2019s answer for forward lookup: 192.168.1.100 as IP address for www.itzgeek.local.<\/strong><\/p>\n<p>Confirm the reverse lookup with dig command.<\/p>\n<pre>dig -x 192.168.1.100<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"bsac bsac-clearfix bsac-post-inline bsac-float-center bsac-align-center bsac-column-1\">\n<div id=\"bsac-25694-1614055777\" class=\"bsac-container bsac-type-code \" data-adid=\"25694\" data-type=\"code\"><\/div>\n<\/div>\n<pre>; &lt;&lt;&gt;&gt; DiG 9.10.3-P4-Debian &lt;&lt;&gt;&gt; -x 192.168.1.100 @192.168.1.10\r\n;; global options: +cmd\r\n;; Got answer:\r\n;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 39795\r\n;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2\r\n\r\n;; OPT PSEUDOSECTION:\r\n; EDNS: version: 0, flags:; udp: 4096\r\n;; QUESTION SECTION:\r\n;100.1.168.192.in-addr.arpa.    IN      PTR\r\n\r\n;; ANSWER SECTION:\r\n<strong>100.1.168.192.in-addr.arpa. 604800 IN   PTR     www.itzgeek.local.<\/strong>\r\n\r\n;; AUTHORITY SECTION:\r\n1.168.192.in-addr.arpa. 604800  IN      NS      ns1.itzgeek.local.\r\n\r\n;; ADDITIONAL SECTION:\r\nns1.itzgeek.local.      604800  IN      A       192.168.1.10\r\n\r\n;; Query time: 0 msec\r\n;; SERVER: 192.168.1.10#53(192.168.1.10)\r\n;; WHEN: Mon Oct 09 13:15:32 EDT 2017\r\n;; MSG SIZE  rcvd: 120\r\n<\/pre>\n<p><strong>The DNS server\u2019s answer for reverse lookup: www.itzgeek.local as a name for 192.168.1.100.<\/strong><\/p>\n<p>This result confirms that both forward and reverse zone lookups are working fine.<\/p>\n<p>That\u2019s All. You have successfully installed BIND on <strong><a href=\"https:\/\/www.itzgeek.com\/tag\/debian-9\">Debian 9<\/a><\/strong> \/ <strong><a href=\"https:\/\/www.itzgeek.com\/tag\/ubuntu-16.04\">Ubuntu 16.04<\/a><\/strong> as a master server. In our next article, we will <strong><a href=\"https:\/\/www.itzgeek.com\/how-tos\/linux\/ubuntu-how-tos\/configure-slave-dns-server-on-debian-9-ubuntu-16-04.html\">configure Slave DNS server<\/a><\/strong> on <strong><a href=\"https:\/\/www.itzgeek.com\/tag\/debian-9\">Debian 9<\/a><\/strong> \/ <strong><a href=\"https:\/\/www.itzgeek.com\/tag\/ubuntu-16.04\">Ubuntu 16.04<\/a><\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Domain Name System (in short, DNS) is an internet service that is used to resolve Domain Name to IP Address and vice versa. BIND (Berkeley Internet Name Domain) provides the functionality of name to ip conversion. This post will help you configure DNS server on Debian 9 \/ Ubuntu 16.04. Environment Domain: itzgeek.local Primary DNS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":621,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-898","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=898"}],"version-history":[{"count":1,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/898\/revisions"}],"predecessor-version":[{"id":899,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/898\/revisions\/899"}],"up":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/621"}],"wp:attachment":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}