{"id":3739,"date":"2014-11-19T12:38:54","date_gmt":"2014-11-19T04:38:54","guid":{"rendered":"http:\/\/rmohan.com\/?p=3739"},"modified":"2014-11-19T12:50:39","modified_gmt":"2014-11-19T04:50:39","slug":"bind-chroot-centos-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3739","title":{"rendered":"BIND CHROOT CENTOS 7"},"content":{"rendered":"<p>BIND (Berkeley Internet Name Daemon) also known as NAMED is the most widely used DNS server in the internet. This tutorial will descibes how we can run BIND in a chroot jail, the process is simply unable to see any part of the filesystem outside the jail. For example, in this post, i will setting up BIND to run chrooted to the directory \/var\/named\/chroot\/. Well, to BIND, 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,<br \/>\nand it\u2019s purposely to enhance the security. Bind Chroot DNS server was by default configured to \/var\/named\/chroot<\/p>\n<p>1. Install Bind Chroot DNS server :<\/p>\n<p>[root@keeplive ~]# yum install bind-chroot bind -y<\/p>\n<p>2. Copy all bind related files to prepare bind chrooted environments :<\/p>\n<p>[root@keeplive ~]# cp -R \/usr\/share\/doc\/bind-*\/sample\/var\/named\/* \/var\/named\/chroot\/var\/named\/<\/p>\n<p>3. Create bind related files into chrooted directory :<\/p>\n<p>[root@keeplive ~]# touch \/var\/named\/chroot\/var\/named\/data\/cache_dump.db<br \/>\n[root@keeplive ~]# touch \/var\/named\/chroot\/var\/named\/data\/named_stats.txt<br \/>\n[root@keeplive ~]# touch \/var\/named\/chroot\/var\/named\/data\/named_mem_stats.txt<br \/>\n[root@keeplive ~]# touch \/var\/named\/chroot\/var\/named\/data\/named.run<br \/>\n[root@keeplive ~]# mkdir \/var\/named\/chroot\/var\/named\/dynamic<br \/>\n[root@keeplive ~]# touch \/var\/named\/chroot\/var\/named\/dynamic\/managed-keys.bind<\/p>\n<p>4. Bind lock file should be writeable, therefore set the permission to make it writable as below :<br \/>\n[root@keeplive ~]# chmod -R 777 \/var\/named\/chroot\/var\/named\/data<br \/>\n[root@keeplive ~]# chmod -R 777 \/var\/named\/chroot\/var\/named\/dynamic<\/p>\n<p>5. Copy \/etc\/named.conf chrooted bind config folder :<br \/>\n[root@keeplive ~]# cp -p \/etc\/named.conf \/var\/named\/chroot\/etc\/named.conf<\/p>\n<p>6.Configure main bind configuration in \/etc\/named.conf. Append the example.local zone information to the file :<br \/>\n[root@keeplive ~]# vi \/var\/named\/chroot\/etc\/named.conf<\/p>\n<p>zone &#8220;rmohan.com&#8221; {<br \/>\n    type master;<br \/>\n    file &#8220;rmohan.zone&#8221;;<br \/>\n};<\/p>\n<p>zone &#8220;1.168.192.in-addr.arpa&#8221; IN {<br \/>\n        type master;<br \/>\n        file &#8220;192.168.1.zone&#8221;;<br \/>\n};<\/p>\n<p>7. Create Forward and Reverse zone files for domain example.local.<\/p>\n<p>a) Create Forward Zone :<br \/>\n[root@keeplive ~]# vi \/var\/named\/chroot\/var\/named\/rmohan.zone<\/p>\n<p>Add the following and save :<br \/>\n;<br \/>\n;       Addresses and other host information.<br \/>\n;<br \/>\n$TTL 86400<br \/>\n@       IN      SOA     rmohan.com. hostmaster.rmohan.com. (<br \/>\n                               2014101901      ; Serial<br \/>\n                               43200      ; Refresh<br \/>\n                               3600       ; Retry<br \/>\n                               3600000    ; Expire<br \/>\n                               2592000 )  ; Minimum<\/p>\n<p>;       Define the nameservers and the mail servers<\/p>\n<p>               IN      NS      ns1.rmohan.com.<br \/>\n               IN      NS      ns2.rmohan.com.<br \/>\n               IN      A       192.168.1.13<br \/>\n               IN      MX      10 mx.rmohan.com.<\/p>\n<p>keeplive         IN      A       192.168.1.13<br \/>\nmx               IN      A       192.168.1.13<br \/>\nns1              IN      A       192.168.1.14<br \/>\nns2              IN      A       192.168.1.15<\/p>\n<p>b) Create Reverse Zone :<br \/>\n[root@keepalive ~]# vi \/var\/named\/chroot\/var\/named\/192.168.1.zone<\/p>\n<p>;<br \/>\n;       Addresses and other host information.<br \/>\n;<br \/>\n$TTL 86400<br \/>\n@       IN      SOA     rmohan.com. hostmaster.rmohan.com. (<br \/>\n                               2014101901      ; Serial<br \/>\n                               43200      ; Refresh<br \/>\n                               3600       ; Retry<br \/>\n                               3600000    ; Expire<br \/>\n                               2592000 )  ; Minimum<\/p>\n<p>1.168.192.in-addr.arpa. IN      NS      keepalive.rmohan.com.<\/p>\n<p>13.0.168.192.in-addr.arpa. IN PTR mx.rmohan.com.<br \/>\n14.0.168.192.in-addr.arpa. IN PTR ns1.rmohan.com.<br \/>\n15.0.168.192.in-addr.arpa. IN PTR ns2.rmohan.com.<\/p>\n<p>8. Stop and disable named service. Start and enable bind-chroot service at boot :<br \/>\n[root@keeplive ~]# \/usr\/libexec\/setup-named-chroot.sh \/var\/named\/chroot on<br \/>\n[root@keeplive ~]# systemctl stop named<br \/>\n[root@keeplive ~]#  systemctl disable named<br \/>\n[root@keeplive ~]#  systemctl start named<br \/>\n[root@keeplive ~]#  systemctl status named<br \/>\nnamed.service &#8211; Berkeley Internet Name Domain (DNS)<br \/>\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/named.service; disabled)<br \/>\n   Active: active (running) since Mon 2014-11-17 08:55:08 SGT; 38s ago<br \/>\n  Process: 16016 ExecStart=\/usr\/sbin\/named -u named $OPTIONS (code=exited, status=0\/SUCCESS)<br \/>\n  Process: 16014 ExecStartPre=\/usr\/sbin\/named-checkconf -z \/etc\/named.conf (code=exited, status=0\/SUCCESS)<br \/>\n Main PID: 16018 (named)<br \/>\n   CGroup: \/system.slice\/named.service<br \/>\n           ??16018 \/usr\/sbin\/named -u named<\/p>\n<p>Nov 17 08:55:09 keeplive named[16018]: error (network unreachable) resolving &#8216;ns.isc.afilias-nst.info\/AAAA\/IN&#8217;: 2001:500:49::1#53<br \/>\nNov 17 08:55:09 keeplive named[16018]: error (network unreachable) resolving &#8216;ns1.isc.ultradns.net\/A\/IN&#8217;: 2001:500:2d::d#53<br \/>\nNov 17 08:55:09 keeplive named[16018]: error (network unreachable) resolving &#8216;ns1.isc.ultradns.net\/AAAA\/IN&#8217;: 2001:500:2d::d#53<br \/>\nNov 17 08:55:10 keeplive named[16018]: error (network unreachable) resolving &#8216;pdns196.ultradns.co.uk\/A\/IN&#8217;: 2001:503:ba3e::2:30#53<br \/>\nNov 17 08:55:10 keeplive named[16018]: error (network unreachable) resolving &#8216;pdns196.ultradns.co.uk\/AAAA\/IN&#8217;: 2001:503:ba3e::2:30#53<br \/>\nNov 17 08:55:10 keeplive named[16018]: error (network unreachable) resolving &#8216;pdns196.ultradns.org\/A\/IN&#8217;: 2001:500:e::1#53<br \/>\nNov 17 08:55:10 keeplive named[16018]: error (network unreachable) resolving &#8216;pdns196.ultradns.org\/AAAA\/IN&#8217;: 2001:500:e::1#53<br \/>\nNov 17 08:55:10 keeplive named[16018]: error (network unreachable) resolving &#8216;ns2.isc.ultradns.net\/AAAA\/IN&#8217;: 2610:a1:1014::e8#53<br \/>\nNov 17 08:55:10 keeplive named[16018]: error (network unreachable) resolving &#8216;pdns196.ultradns.org\/AAAA\/IN&#8217;: 2001:502:4612::e8#53<br \/>\nNov 17 08:55:10 keeplive named[16018]: error (network unreachable) resolving &#8216;pdns196.ultradns.com\/A\/IN&#8217;: 2610:a1:1016::e8#53<\/p>\n<p>[root@keeplive ~]# systemctl status named-chroot.service<br \/>\nnamed-chroot.service &#8211; Berkeley Internet Name Domain (DNS)<br \/>\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/named-chroot.service; disabled)<br \/>\n   Active: failed (Result: exit-code) since Mon 2014-11-17 08:56:15 SGT; 11s ago<br \/>\n  Process: 16052 ExecStart=\/usr\/sbin\/named -u named -t \/var\/named\/chroot $OPTIONS (code=exited, status=1\/FAILURE)<br \/>\n  Process: 16050 ExecStartPre=\/usr\/sbin\/named-checkconf -t \/var\/named\/chroot -z \/etc\/named.conf (code=exited, status=0\/SUCCESS)<\/p>\n<p>Nov 17 08:56:15 keeplive named[16054]: automatic empty zone: A.E.F.IP6.ARPA<br \/>\nNov 17 08:56:15 keeplive named[16054]: automatic empty zone: B.E.F.IP6.ARPA<br \/>\nNov 17 08:56:15 keeplive named[16054]: automatic empty zone: 8.B.D.0.1.0.0.2.IP6.ARPA<br \/>\nNov 17 08:56:15 keeplive named[16054]: couldn&#8217;t add command channel 127.0.0.1#953: address in use<br \/>\nNov 17 08:56:15 keeplive named[16054]: couldn&#8217;t add command channel ::1#953: address in use<br \/>\nNov 17 08:56:15 keeplive named[16054]: isc_stdio_open &#8216;data\/named.run&#8217; failed: permission denied<br \/>\nNov 17 08:56:15 keeplive named[16054]: configuring logging: permission denied<br \/>\nNov 17 08:56:15 keeplive systemd[1]: named-chroot.service: control process exited, code=exited status=1<br \/>\nNov 17 08:56:15 keeplive systemd[1]: Failed to start Berkeley Internet Name Domain (DNS).<br \/>\nNov 17 08:56:15 keeplive systemd[1]: Unit named-chroot.service entered failed state.<br \/>\n[root@keeplive ~]# systemctl enable named-chroot<br \/>\nln -s &#8216;\/usr\/lib\/systemd\/system\/named-chroot.service&#8217; &#8216;\/etc\/systemd\/system\/multi-user.target.wants\/named-chroot.service&#8217;<br \/>\n[root@keeplive ~]# systemctl status named-chroot.service<br \/>\nnamed-chroot.service &#8211; Berkeley Internet Name Domain (DNS)<br \/>\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/named-chroot.service; enabled)<br \/>\n   Active: failed (Result: exit-code) since Mon 2014-11-17 08:56:15 SGT; 30s ago<\/p>\n<p>Nov 17 08:56:15 keeplive named[16054]: automatic empty zone: A.E.F.IP6.ARPA<br \/>\nNov 17 08:56:15 keeplive named[16054]: automatic empty zone: B.E.F.IP6.ARPA<br \/>\nNov 17 08:56:15 keeplive named[16054]: automatic empty zone: 8.B.D.0.1.0.0.2.IP6.ARPA<br \/>\nNov 17 08:56:15 keeplive named[16054]: couldn&#8217;t add command channel 127.0.0.1#953: address in use<br \/>\nNov 17 08:56:15 keeplive named[16054]: couldn&#8217;t add command channel ::1#953: address in use<br \/>\nNov 17 08:56:15 keeplive named[16054]: isc_stdio_open &#8216;data\/named.run&#8217; failed: permission denied<br \/>\nNov 17 08:56:15 keeplive named[16054]: configuring logging: permission denied<br \/>\nNov 17 08:56:15 keeplive systemd[1]: named-chroot.service: control process exited, code=exited status=1<br \/>\nNov 17 08:56:15 keeplive systemd[1]: Failed to start Berkeley Internet Name Domain (DNS).<br \/>\nNov 17 08:56:15 keeplive systemd[1]: Unit named-chroot.service entered failed state.<\/p>\n<p>[root@keeplive ~]# systemctl enable named-chroot<br \/>\nln -s &#8216;\/usr\/lib\/systemd\/system\/named-chroot.service&#8217; &#8216;\/etc\/systemd\/system\/multi-user.target.wants\/named-chroot.service&#8217;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>BIND (Berkeley Internet Name Daemon) also known as NAMED is the most widely used DNS server in the internet. This tutorial will descibes how we can run BIND in a chroot jail, the process is simply unable to see any part of the filesystem outside the jail. For example, in this post, i will setting [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,50],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3739"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3739"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3739\/revisions"}],"predecessor-version":[{"id":3740,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3739\/revisions\/3740"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}