{"id":3274,"date":"2012-06-02T15:30:59","date_gmt":"2012-06-02T07:30:59","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=3274"},"modified":"2023-04-28T09:49:16","modified_gmt":"2023-04-28T09:49:16","slug":"how-to-setup-private-dns-with-bind9-chroot-on-centos-6-2-vps","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-setup-private-dns-with-bind9-chroot-on-centos-6-2-vps\/","title":{"rendered":"How to Setup Private DNS With Bind9 Chroot on CentOS 6.2 VPS"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/06\/bind.jpg\" alt=\"dns\" title=\"dns\" width=\"139\" height=\"140\" class=\"alignleft size-full wp-image-3276 lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/06\/bind.jpg 139w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2012\/06\/bind-100x100.jpg 100w\" data-sizes=\"(max-width: 139px) 100vw, 139px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 139px; --smush-placeholder-aspect-ratio: 139\/140;\" \/>Assumed that you already buy two Virtual Private Server (VPS) but you dont want to point your nameservers on your hosting provider. To look more professional and stylish, you can run and have two private nameservers such as ns1.ehowstuff.local and ns2.ehowstuff.local. This post will show you the steps on how to setup and run your own Bind9 Chroot private nameservers on CentOS 6.2 VPS or dedicated server with atleast 2 IP addresses. To fit you requirement, please replace domain (ehowstuff.local) and ip addresses to your own domain and IPs.<\/p>\n<h2>ns1.ehowstuff.local : 192.168.1.44 (Master Private DNS server)<br \/>\nns2.ehowstuff.local : 192.168.1.54 (Slave Private DNS server)<\/h2>\n<p>1. Install Bind Chroot DNS Server on both Primary and Slave server :<\/p>\n<h2>Master DNS Server<\/h2>\n<pre>\n[root@ns1 ~]# yum install bind-chroot -y\n<\/pre>\n<h2>Slave DNS server<\/h2>\n<pre>\n[root@ns2 ~]# yum install bind-chroot -y\n<\/pre>\n<p><\/br><\/p>\n<h2>Master DNS Server<\/h2>\n<p><\/br><br \/>\n2. Login to Primary DNS server (ns1), and create a file \/var\/named\/chroot\/var\/named\/ehowstuff.local with the following configuration:<\/p>\n<pre>\n[root@ns1 ~]# vim \/var\/named\/chroot\/var\/named\/ehowstuff.local\n<\/pre>\n<pre>\n;\n;       Addresses and other host information.\n;\n$TTL 14400\nehowstuff.local.        IN      SOA     ns1.ehowstuff.local.    admin.ehowstuff.local. (\n                                        2012060201      ; Serial\n                                        86400      ; Refresh\n                                        7200       ; Retry\n                                        3600000    ; Expire\n                                        86400 )  ; Minimum\n\n;A record for domain mapping domain to IP\nehowstuff.local.        IN      A       192.168.1.44\n\n;Define the atleast 2 private nameservers\nehowstuff.local.        IN      NS      ns1.ehowstuff.local.\nehowstuff.local.        IN      NS      ns2.ehowstuff.local.\n\n; Map 2 private nameservers to IP addressess using A record\nns1     IN      A       192.168.1.44\nns2     IN      A       192.168.1.54\n\n; Specify subdomains if any using CNAME or alias.\nwww     IN      CNAME   ehowstuff.local.\nftp     IN      CNAME   ehowstuff.local.\n\n; Mail exhanger and map it IP using A record.\nehowstuff.local.        IN      MX      10      mail.ehowstuff.local.\n<\/pre>\n<p>3. Still on ns1, please generate an RNDC key :<br \/>\nThe rndc tool is used to managed the named daemon. We need to generate a keyfile called \/etc\/rndc.key which is referenced both by \/etc\/rndc.conf and \/etc\/named.conf To do this we use the following command; <\/p>\n<pre>\n[root@ns1 ~]# rndc-confgen -a -c \/etc\/rndc.key\nwrote key file \"\/etc\/rndc.key\"\n<\/pre>\n<p>View the content of the RNDC key :<\/p>\n<pre>\n[root@ns1 ~]# cat \/etc\/rndc.key\nkey \"rndc-key\" {\n        algorithm hmac-md5;\n        secret \"T6tduqyMQ\/YbIDXOmE0Fzg==\";\n};\n<\/pre>\n<p>4. on ns1, edit the \/var\/named\/chroot\/etc\/named.conf file for ehowstuff.local<\/p>\n<pre>\n[root@ns1 ~]# vi \/var\/named\/chroot\/etc\/named.conf\n<\/pre>\n<pre>\noptions {\n       directory \"\/var\/named\";\n       dump-file \"\/var\/named\/data\/cache_dump.db\";\n       statistics-file \"\/var\/named\/data\/named_stats.txt\";\nforwarders { 8.8.8.8; };\n};\ninclude \"\/etc\/rndc.key\";\n\/\/ We are the master server for ehowstuff.local\n\nzone \"ehowstuff.local\" {\n        type master;\n        file \"\/var\/named\/ehowstuff.local\";\n        allow-transfer {192.168.1.54;};\n        allow-update {none;};\n};\n<\/pre>\n<p>5. Start the DNS service using the following command :<\/p>\n<pre>\n[root@ns1 ~]# \/etc\/init.d\/named start\nStarting named:                                            [  OK  ]\n<\/pre>\n<p>6. Make named daemon auto start during boot :<\/p>\n<pre>\n[root@ns1 ~]# chkconfig named on\n<\/pre>\n<p><\/br><\/p>\n<h2>Slave DNS Server<\/h2>\n<p><\/br><br \/>\n7. Making slave DNS server can be so easy. Login to the other DNS server(ns2) and open the named.conf file. You need not create any file as the slave will automatically download the master zone information through zone transfer. After sometime, you can view the zone file. :<\/p>\n<pre>\n[root@ns2 ~]# vi \/var\/named\/chroot\/etc\/named.conf\n<\/pre>\n<pre>\nzone \"ehowstuff.local\" {\ntype slave;\nfile \"\/var\/named\/slaves\/ehowstuff.local\";\nmasters {192.168.1.44;};\n};\n<\/pre>\n<p><strong>Note<\/strong>: Bind will not allow you to run master and slave on same server, even-though you have 2 IP addresses<\/p>\n<p>8. Start the DNS service using the following command :<\/p>\n<pre>\n[root@ns2 ~]# \/etc\/init.d\/named start\nStarting named:                                            [  OK  ]\n<\/pre>\n<p>9. Make named daemon auto start during boot :<\/p>\n<pre>\n[root@ns2 ~]# chkconfig named on\n<\/pre>\n<p>10. Before testing, make sure your pc or server using the Bind Chroot DNS Server that has been set up :<\/p>\n<pre>\n[root@ns1 ~]# cat \/etc\/resolv.conf\nnameserver 192.168.1.44\nnameserver 192.168.1.54\n<\/pre>\n<pre>\n[root@ns2 ~]# cat \/etc\/resolv.conf\nnameserver 192.168.1.44\nnameserver 192.168.1.54\n<\/pre>\n<p>11. Test your DNS service :<\/p>\n<p>Test from Master DNS server (ns1)<\/p>\n<pre>\n[root@ns1 ~]# dig ehowstuff.local\n\n; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6_2.2 <<>> ehowstuff.local\n;; global options: +cmd\n;; Got answer:\n;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25783\n;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2\n\n;; QUESTION SECTION:\n;ehowstuff.local.               IN      A\n\n;; ANSWER SECTION:\nehowstuff.local.        14400   IN      A       192.168.1.44\n\n;; AUTHORITY SECTION:\nehowstuff.local.        14400   IN      NS      ns1.ehowstuff.local.\nehowstuff.local.        14400   IN      NS      ns2.ehowstuff.local.\n\n;; ADDITIONAL SECTION:\nns1.ehowstuff.local.    14400   IN      A       192.168.1.44\nns2.ehowstuff.local.    14400   IN      A       192.168.1.54\n\n;; Query time: 0 msec\n;; SERVER: 192.168.1.44#53(192.168.1.44)\n;; WHEN: Sat Jun  2 14:46:46 2012\n;; MSG SIZE  rcvd: 117\n<\/pre>\n<pre>\n[root@ns1 ~]# host -t mx ehowstuff.local\n<\/pre>\n<pre>\nehowstuff.local mail is handled by 10 mail.ehowstuff.local.\n<\/pre>\n<pre>\n[root@ns1 ~]# host -t ns ehowstuff.local\n<\/pre>\n<pre>\nehowstuff.local name server ns2.ehowstuff.local.\nehowstuff.local name server ns1.ehowstuff.local.\n<\/pre>\n<p>Test from Slave DNS server (ns2)<\/p>\n<pre>\n[root@ns2 ~]# dig ehowstuff.local\n\n; <<>> DiG 9.7.3-P3-RedHat-9.7.3-8.P3.el6_2.2 <<>> ehowstuff.local\n;; global options: +cmd\n;; Got answer:\n;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11526\n;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2\n\n;; QUESTION SECTION:\n;ehowstuff.local.               IN      A\n\n;; ANSWER SECTION:\nehowstuff.local.        14400   IN      A       192.168.1.44\n\n;; AUTHORITY SECTION:\nehowstuff.local.        14400   IN      NS      ns2.ehowstuff.local.\nehowstuff.local.        14400   IN      NS      ns1.ehowstuff.local.\n\n;; ADDITIONAL SECTION:\nns1.ehowstuff.local.    14400   IN      A       192.168.1.44\nns2.ehowstuff.local.    14400   IN      A       192.168.1.54\n\n;; Query time: 3 msec\n;; SERVER: 127.0.0.1#53(127.0.0.1)\n;; WHEN: Sat Jun  2 15:26:19 2012\n;; MSG SIZE  rcvd: 117\n<\/pre>\n<pre>\n[root@ns2 ~]# host -t mx ehowstuff.local\n<\/pre>\n<pre>\nehowstuff.local mail is handled by 10 mail.ehowstuff.local.\n<\/pre>\n<pre>\n[root@ns2 ~]# host -t ns ehowstuff.local\n<\/pre>\n<pre>\nehowstuff.local name server ns2.ehowstuff.local.\nehowstuff.local name server ns1.ehowstuff.local.\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Assumed that you already buy two Virtual Private Server (VPS) but you dont want to point your nameservers on your hosting provider. To look more professional and stylish, you can&#8230;<\/p>\n","protected":false},"author":6,"featured_media":3276,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1111,2055,1138],"tags":[1228,1280,1337,1536,1670],"class_list":["post-3274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bind9","category-centos","category-dns","tag-bind","tag-chroot","tag-dns","tag-linux","tag-private-nameservers"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/3274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=3274"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/3274\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/3276"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=3274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=3274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=3274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}