{"id":5551,"date":"2014-10-22T15:09:18","date_gmt":"2014-10-22T07:09:18","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=5551"},"modified":"2023-04-28T09:47:26","modified_gmt":"2023-04-28T09:47:26","slug":"bind-dns-server-in-chroot-jail-on-centos-7","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/bind-dns-server-in-chroot-jail-on-centos-7\/","title":{"rendered":"How to Setup Bind DNS Server in Chroot Jail on CentOS 7"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone wp-image-6834 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2014\/10\/How-to-Setup-Bind-DNS-Server-in-Chroot-Jail-on-CentOS-7.jpg\" alt=\"bind dns\" width=\"1920\" height=\"1080\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2014\/10\/How-to-Setup-Bind-DNS-Server-in-Chroot-Jail-on-CentOS-7.jpg 1920w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2014\/10\/How-to-Setup-Bind-DNS-Server-in-Chroot-Jail-on-CentOS-7-300x169.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2014\/10\/How-to-Setup-Bind-DNS-Server-in-Chroot-Jail-on-CentOS-7-768x432.jpg 768w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2014\/10\/How-to-Setup-Bind-DNS-Server-in-Chroot-Jail-on-CentOS-7-1024x576.jpg 1024w\" data-sizes=\"(max-width: 1920px) 100vw, 1920px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1920px; --smush-placeholder-aspect-ratio: 1920\/1080;\" \/><\/p>\n<p>BIND (Berkeley Internet Name Daemon) also known as NAMED is the most widely used linux dns server in the internet.<\/p>\n<p>This tutorial will explain how we can setup BIND DNS in a chroot jail in CentOS 7, the process is simply unable to see any part of the filesystem outside the jail. For example, in this post, i will configure BIND dns to run chrooted to the directory \/var\/named\/chroot\/.<\/p>\n<p>Well, to BIND dns, the contents of this directory will appear to be \/, the root directory. A \u201cjail\u201d is a software mechanism for limiting the ability of a process to access resources outside a very limited area, and it\u2019s purposely to enhance the security.<\/p>\n<p>Unlike with earlier versions of BIND, you typically will not need to compile named statically nor install shared libraries under the new root.<\/p>\n<p>Chroot Environment initialization script will mount the above configuration files using the mount &#8211;bind command, so that you can manage the configuration outside this environment. There is no need to copy anything into the \/var\/named\/chroot\/ directory because it is mounted automatically. This simplifies maintenance since you do not need to take any special care of BIND configuration files if it is run in a chroot environment. You can organize everything as you would with BIND not running in a chroot environment.<\/p>\n<p>Chrooted Bind DNS server was by default configured to \/var\/named\/chroot. You may follow this complete steps to implement Bind Chroot DNS Server on CentOS 7 virtual private server (VPS).<\/p>\n<h3>Setup Bind DNS Server in Chroot Jail on CentOS 7<\/h3>\n<p>1. Install Bind Chroot DNS server :<\/p>\n<pre># yum install bind-chroot -y\n<\/pre>\n<p>2. To enable the named-chroot service, first check if the named service is running by issuing the following command:<\/p>\n<pre>\n# systemctl status named\n<\/pre>\n<p>If it is running, it must be disabled.<br \/>\nTo disable named, issue the following commands as root:<\/p>\n<pre>\n# systemctl stop named\n<\/pre>\n<pre>\n# systemctl disable named\n<\/pre>\n<p>3. Initialize the \/var\/named\/chroot environment by running:<\/p>\n<pre># \/usr\/libexec\/setup-named-chroot.sh \/var\/named\/chroot on\n# systemctl stop named\n# systemctl disable named\n# systemctl start named-chroot\n# systemctl enable named-chroot\nln -s '\/usr\/lib\/systemd\/system\/named-chroot.service' '\/etc\/systemd\/system\/multi-user.target.wants\/named-chroot.service'\n<\/pre>\n<p>The following directories are automatically mounted into the \/var\/named\/chroot\/ directory if the corresponding mount point directories underneath \/var\/named\/chroot\/ are empty:<\/p>\n<p>Verify Chroot Environment :<\/p>\n<pre>\n# ll \/var\/named\/chroot\/etc\ntotal 28\n-rw-r--r-- 1 root root   372 Dec  1 23:04 localtime\ndrwxr-x--- 2 root named 4096 Nov 22 01:28 named\n-rw-r----- 1 root named 1705 Mar 22  2016 named.conf\n-rw-r--r-- 1 root named 2389 Nov 22 01:28 named.iscdlv.key\n-rw-r----- 1 root named  931 Jun 21  2007 named.rfc1912.zones\n-rw-r--r-- 1 root named  487 Jul 19  2010 named.root.key\ndrwxr-x--- 3 root named 4096 Jan  4 22:12 pki\n<\/pre>\n<pre>\n# ll \/var\/named\/chroot\/var\/named\ntotal 32\ndrwxr-x--- 7 root  named 4096 Jan  4 22:12 chroot\ndrwxrwx--- 2 named named 4096 Nov 22 01:28 data\ndrwxrwx--- 2 named named 4096 Nov 22 01:28 dynamic\n-rw-r----- 1 root  named 2076 Jan 28  2013 named.ca\n-rw-r----- 1 root  named  152 Dec 15  2009 named.empty\n-rw-r----- 1 root  named  152 Jun 21  2007 named.localhost\n-rw-r----- 1 root  named  168 Dec 15  2009 named.loopback\ndrwxrwx--- 2 named named 4096 Nov 22 01:28 slaves\n<\/pre>\n<p>4. Create bind dns related files into chrooted directory :<\/p>\n<pre># touch \/var\/named\/chroot\/var\/named\/data\/cache_dump.db\n# touch \/var\/named\/chroot\/var\/named\/data\/named_stats.txt\n# touch \/var\/named\/chroot\/var\/named\/data\/named_mem_stats.txt\n# touch \/var\/named\/chroot\/var\/named\/data\/named.run\n# mkdir \/var\/named\/chroot\/var\/named\/dynamic\n# touch \/var\/named\/chroot\/var\/named\/dynamic\/managed-keys.bind\n<\/pre>\n<p>5. Bind lock file should be writeable, therefore set the permission to make it writable as below :<\/p>\n<pre># chmod -R 777 \/var\/named\/chroot\/var\/named\/data\n# chmod -R 777 \/var\/named\/chroot\/var\/named\/dynamic\n<\/pre>\n<p>6. Copy \/etc\/named.conf chrooted bind config folder :<\/p>\n<pre># cp -p \/etc\/named.conf \/var\/named\/chroot\/etc\/named.conf\n<\/pre>\n<p>7.Configure main bind configuration in \/etc\/named.conf. Append the example.local zone information to the file :<\/p>\n<pre># vi \/var\/named\/chroot\/etc\/named.conf\n<\/pre>\n<p>Create forward and reverse zone into named.conf:<\/p>\n<pre>..\n..\nzone \"example.local\" {\n    type master;\n    file \"example.local.zone\";\n};\n\nzone \"0.168.192.in-addr.arpa\" IN {\n        type master;\n        file \"192.168.0.zone\";\n};\n..\n..\n<\/pre>\n<p>Full named.conf configuration :<\/p>\n<pre>\/\/\n\/\/ named.conf\n\/\/\n\/\/ Provided by Red Hat bind package to configure the ISC BIND named(8) DNS\n\/\/ server as a caching only nameserver (as a localhost DNS resolver only).\n\/\/\n\/\/ See \/usr\/share\/doc\/bind*\/sample\/ for example named configuration files.\n\/\/\n\noptions {\n        <strong>listen-on port 53 { any; };<\/strong>\n        listen-on-v6 port 53 { ::1; };\n        directory       \"\/var\/named\";\n        dump-file       \"\/var\/named\/data\/cache_dump.db\";\n        statistics-file \"\/var\/named\/data\/named_stats.txt\";\n        memstatistics-file \"\/var\/named\/data\/named_mem_stats.txt\";\n        <strong>allow-query     { any; };<\/strong>\n\n        \/*\n         - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.\n         - If you are building a RECURSIVE (caching) DNS server, you need to enable\n           recursion.\n         - If your recursive DNS server has a public IP address, you MUST enable access\n           control to limit queries to your legitimate users. Failing to do so will\n           cause your server to become part of large scale DNS amplification\n           attacks. Implementing BCP38 within your network would greatly\n           reduce such attack surface\n        *\/\n        recursion yes;\n\n        dnssec-enable yes;\n        dnssec-validation yes;\n        dnssec-lookaside auto;\n\n        \/* Path to ISC DLV key *\/\n        bindkeys-file \"\/etc\/named.iscdlv.key\";\n\n        managed-keys-directory \"\/var\/named\/dynamic\";\n\n        pid-file \"\/run\/named\/named.pid\";\n        session-keyfile \"\/run\/named\/session.key\";\n};\n\nlogging {\n        channel default_debug {\n                file \"data\/named.run\";\n                severity dynamic;\n        };\n};\n\nzone \".\" IN {\n        type hint;\n        file \"named.ca\";\n};\n\n<strong>zone \"example.local\" {\n    type master;\n    file \"example.local.zone\";\n};\n\nzone \"0.168.192.in-addr.arpa\" IN {\n        type master;\n        file \"192.168.0.zone\";\n};<\/strong>\n\ninclude \"\/etc\/named.rfc1912.zones\";\ninclude \"\/etc\/named.root.key\";\n<\/pre>\n<p>8. Create Forward and Reverse zone files for domain example.local.<\/p>\n<p>a) Create Forward Zone :<\/p>\n<pre># vi \/var\/named\/chroot\/var\/named\/example.local.zone\n<\/pre>\n<p>Add the following and save :<\/p>\n<pre>;\n;       Addresses and other host information.\n;\n$TTL 86400\n@       IN      SOA     example.local. hostmaster.example.local. (\n                               2014101901      ; Serial\n                               43200      ; Refresh\n                               3600       ; Retry\n                               3600000    ; Expire\n                               2592000 )  ; Minimum\n\n;       Define the nameservers and the mail servers\n\n               IN      NS      ns1.example.local.\n               IN      NS      ns2.example.local.\n               IN      A       192.168.0.70\n               IN      MX      10 mx.example.local.\n\ncentos7          IN      A       192.168.0.70\nmx               IN      A       192.168.0.50\nns1              IN      A       192.168.0.70\nns2              IN      A       192.168.0.80\n<\/pre>\n<p>b) Create Reverse Zone :<\/p>\n<pre># vi \/var\/named\/chroot\/var\/named\/192.168.0.zone\n<\/pre>\n<pre>;\n;       Addresses and other host information.\n;\n$TTL 86400\n@       IN      SOA     example.local. hostmaster.example.local. (\n                               2014101901      ; Serial\n                               43200      ; Refresh\n                               3600       ; Retry\n                               3600000    ; Expire\n                               2592000 )  ; Minimum\n\n0.168.192.in-addr.arpa. IN      NS      centos7.example.local.\n\n70.0.168.192.in-addr.arpa. IN PTR mx.example.local.\n70.0.168.192.in-addr.arpa. IN PTR ns1.example.local.\n80.0.168.192.in-addr.arpa. IN PTR ns2.example.local.\n<\/pre>\n<h4>Bind dns related articles<\/h4>\n<ul>\n<li><a href=\"https:\/\/webhostinggeeks.com\/howto\/how-to-configure-bind-chroot-logging-on-centos-6-2\/\" target=\"_blank\" rel=\"nofollow noopener\">How to Configure Bind-Chroot Logging on CentOS 6.2<\/a><\/li>\n<li><a href=\"https:\/\/webhostinggeeks.com\/howto\/how-to-install-and-configure-bind9-dns-on-ubuntu-11-10\/\" target=\"_blank\" rel=\"nofollow noopener\">How to Install and Configure Bind9 DNS on Ubuntu 11.10<\/a><\/li>\n<li><a href=\"https:\/\/webhostinggeeks.com\/howto\/how-to-install-and-configure-bind-9-as-a-caching-server-on-ubuntu-11-10\/\" target=\"_blank\" rel=\"nofollow noopener\">How to Install and Configure Bind 9 as a Caching Server on Ubuntu 11.10<\/a><\/li>\n<\/ul>\n<p><em><strong>Reference :<\/strong><\/em><br \/>\n<em><a href=\"https:\/\/docs.centos.org\/2\/rhl-rg-en-7.2\/ch-bind.html\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/www.centos.org\/docs\/2\/rhl-rg-en-7.2\/ch-bind.html<\/a><\/em><br \/>\n<em> <a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/5\/html\/Deployment_Guide\/ch-bind.html\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/5\/html\/Deployment_Guide\/ch-bind.html<\/a><\/em><br \/>\n<em><a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/7\/html\/Networking_Guide\/sec-BIND.html\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/7\/html\/Networking_Guide\/sec-BIND.html<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>BIND (Berkeley Internet Name Daemon) also known as NAMED is the most widely used linux dns server in the internet. This tutorial will explain how we can setup BIND DNS&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6834,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1111,2055],"tags":[1228,1258,1280,1337,1536,1670],"class_list":["post-5551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bind9","category-centos","tag-bind","tag-centos-7","tag-chroot","tag-dns","tag-linux","tag-private-nameservers"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5551","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=5551"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5551\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6834"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=5551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=5551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=5551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}