{"id":100,"date":"2020-08-28T03:05:30","date_gmt":"2020-08-28T03:05:30","guid":{"rendered":"https:\/\/webhostingnoida.in\/blog\/?p=100"},"modified":"2021-06-28T03:08:05","modified_gmt":"2021-06-28T03:08:05","slug":"how-to-install-and-configure-dns-server-in-linux-centos-ubuntu","status":"publish","type":"post","link":"https:\/\/webhostingnoida.in\/blog\/how-to-install-and-configure-dns-server-in-linux-centos-ubuntu\/","title":{"rendered":"How to Install and Configure DNS Server in Linux &#8211; Centos\/ubuntu"},"content":{"rendered":"<p>Domain Name Service (DNS) is an internet service that maps IP addresses to fully qualified domain names (FQDN) and vice versa.<\/p>\n<p>BIND stands for Berkley Internet Naming Daemon.<\/p>\n<p>BIND is the most common program used for maintaining a name server on Linux.<\/p>\n<p>In this tutorial, we will explain how to install and configure a DNS server.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-install-and-configure-dns-server-in-linux-centos-ubuntu\/#Install_Bind\" >Install Bind<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-install-and-configure-dns-server-in-linux-centos-ubuntu\/#IPv4_Mode\" >IPv4 Mode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-install-and-configure-dns-server-in-linux-centos-ubuntu\/#Creating_Zones_entries\" >Creating Zones entries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-install-and-configure-dns-server-in-linux-centos-ubuntu\/#Creating_zone_files\" >Creating zone files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/webhostingnoida.in\/blog\/how-to-install-and-configure-dns-server-in-linux-centos-ubuntu\/#Test_the_DNS_server\" >Test the DNS server<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Install_Bind\"><\/span>Install Bind<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Install the bind9 package using the appropriate package management utilities for your Linux distributions.<\/p>\n<p>On Debian\/Ubuntu flavors, do the following:<\/p>\n<pre><strong> sudo apt-get install bind9<\/strong><\/pre>\n<p>On Redhat\/CentOS\/Fedora flavors, do the following:<\/p>\n<pre><strong> yum install bind9<\/strong><\/pre>\n<p>All the DNS configurations are stored under \/etc\/bind directory. The primary configuration is \/etc\/bind\/named.conf which will include other needed files. The file named \/etc\/bind\/db.root describes the root nameservers in the world.<\/p>\n<h3 id=\"ipv4-mode\"><span class=\"ez-toc-section\" id=\"IPv4_Mode\"><\/span>IPv4 Mode<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Before continuing, let\u2019s set BIND to IPv4 mode. On both servers, edit the <code>bind9<\/code> service parameters file:<\/p>\n<pre><strong>sudo vi \/etc\/default\/bind9<\/strong><\/pre>\n<p><span style=\"font-size: 1rem;\">Add \u201c-4\u201d to the <\/span><code>OPTIONS<\/code><span style=\"font-size: 1rem;\"> variable. It should look like the following &#8211; \/etc\/default\/bind9<\/span><\/p>\n<div class=\"code-toolbar\">\n<div class=\"context\">\n<pre class=\"code-pre language-bash\"><strong><code class=\"code-highlight language-bash\"><span class=\"token assign-left variable\">OPTIONS<\/span><span class=\"token operator\">=<\/span><span class=\"token string\">\"-4 -u bind\"<\/span><\/code><\/strong><\/pre>\n<p><span style=\"font-size: 1rem;\">Save and exit.<\/span><\/p>\n<\/div>\n<\/div>\n<p>Now that BIND is installed, let\u2019s configure the primary DNS server.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Creating_Zones_entries\"><\/span>Creating Zones entries<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Firstly we will create a forward zone entry in \/etc\/named.conf for our domain webhostingnoida.com. Add the following lines in named.conf<\/p>\n<pre><strong>zone \"webhostingnoida.com\" IN {\r\ntype master;\r\nfile \"fwd.webhostingnoida.com.db\";\r\nallow-update { none; };\r\n};<\/strong><\/pre>\n<p>Here,<strong> \u2018webhostingnoida.com\u2019<\/strong> is the Domain name,<\/p>\n<p><strong>\u2018master\u2019<\/strong> is the Primary DNS,<\/p>\n<p><strong>fwd.webhostingnoida.com.db<\/strong> is the Forward lookup file,<\/p>\n<p><strong>\u2018allow-update\u2019<\/strong> will be none, its the primary DNS.<\/p>\n<p>Similarly, we will now create an entry for reverse zone as well in\u201dnamed.conf\u201d<\/p>\n<pre><strong>zone \"1.168.192.in-addr.arpa\" IN {\r\ntype master;\r\nfile \"1.168.192.db\";\r\nallow-update { none; };\r\n};<\/strong><\/pre>\n<p>Here,<\/p>\n<p><strong>1.168.192.in-addr.arpa<\/strong>\u00a0 is Reverse lookup name,<\/p>\n<p><strong>master<\/strong>\u00a0is for Primary DNS,<\/p>\n<p><strong>1.168.192.db<\/strong>\u00a0is the\u00a0reverse lookup file,<\/p>\n<p><strong>allow-update<\/strong> \u2013 will be set to none, since this is the primary DNS.<\/p>\n<p>Our configuration for \u201cnamed.conf\u201d is complete &amp; next we will create zone files for our BIND server.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Creating_zone_files\"><\/span><strong><b>Creating zone files<\/b><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>We will first create our forward zone file i.e \u201c<strong>fwd.webhostingnoida.com.db<\/strong>\u201d in \u201c<strong>\/var\/named<\/strong>\u201d folder and then will make the following entries in it<\/p>\n<pre><strong>$TTL 86400\r\n@ IN SOA primary.webhostingnoida.com. root.webhostingnoida.com. (\r\n2014112511 ;Serial\r\n3600 ;Refresh\r\n1800 ;Retry\r\n604800 ;Expire\r\n86400 ;Minimum TTL\r\n)\r\n;Name Server Information\r\n@ IN NS primary.webhostingnoida.com.\r\n;IP address of Name Server\r\nprimary IN A 192.168.1.100\r\n;Mail exchanger\r\nwebhostingnoida.com. IN MX 10 mail.webhostingnoida.com.\r\n;A - Record HostName To Ip Address\r\nwww IN A 192.168.1.105\r\nmail IN A 192.168.1.120\r\n;CNAME record\r\nftp IN CNAME www.webhostingnoida.com.<\/strong><\/pre>\n<p>Similarly, we will create reverse zone file named \u201c<em><strong>1.168.192.db\u201d<\/strong><\/em> in \u201c<em><strong>\/var\/named<\/strong><\/em>\u201d folder with the following content<\/p>\n<pre><strong>vi \/var\/named\/1.168.192.db<\/strong><\/pre>\n<div>\n<pre><strong>$TTL 86400\r\n@ IN SOA dns.ltechlab.com. root.ltechlab.com. (\r\n2014112511 ;Serial\r\n3600 ;Refresh\r\n1800 ;Retry\r\n604800 ;Expire\r\n86400 ;Minimum TTL\r\n)\r\n;Name Server Information\r\n@ IN NS dns.ltechlab.com.\r\n;Reverse lookup for Name Server\r\n8 IN PTR dns.ltechlab.com.\r\n;PTR Record IP address to HostName\r\n105 IN PTR www.ltechlab.com.\r\n120 IN PTR mail.ltechlab.com.<\/strong><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>After creating these zone files, we will restart our BIND server<\/p>\n<pre><strong>service named restart or\r\nsystemctl restart named.service<\/strong><\/pre>\n<p>Now, we will verify our zone files.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Test_the_DNS_server\"><\/span>Test the DNS server<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Now we have configured the DNS server for our domain. We will test our DNS server by pinging mail.webhostingnoida.com from web.webhostingnoida.com.<\/p>\n<p>If the ping is success, then we have configured the DNS successfully.<\/p>\n<p>You can also use nslookup and dig to test DNS servers.<\/p>\n<p>On web.webhostingnoida.com server, add the following to \/etc\/resolv.conf<\/p>\n<pre><strong>nameserver 10.42.0.83<\/strong><\/pre>\n<p>Now ping, mail.webhostingnoida.com, which should resolve the address appropriately from the DNS server that we just configured.<\/p>\n<pre><strong>$ ping mail.thegeekstuff.net\r\n\r\nPING mail.thegeekstuff.net (10.42.0.70) 56(84) bytes of data.\r\n64 bytes from mail.thegeekstuff.net (10.42.0.70): icmp_req=1 ttl=64 time=0.482 ms\r\n64 bytes from mail.thegeekstuff.net (10.42.0.70): icmp_req=2 ttl=64 time=0.532 ms<\/strong><\/pre>\n<p>Hope you like this blog<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Domain Name Service (DNS) is an internet service that maps IP addresses to fully qualified domain names (FQDN) and vice versa. BIND stands for Berkley Internet Naming Daemon. BIND is the most common program used for maintaining a name server on Linux. In this tutorial, we will explain how to install and configure a DNS<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-dns-configuration"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":2,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/posts\/100\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostingnoida.in\/blog\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}