
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 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/.
Well, to BIND dns, the contents of this directory will appear to be /, the root directory. A “jail” is a software mechanism for limiting the ability of a process to access resources outside a very limited area, and it’s purposely to enhance the security.
Unlike with earlier versions of BIND, you typically will not need to compile named statically nor install shared libraries under the new root.
Chroot Environment initialization script will mount the above configuration files using the mount –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.
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).
Setup Bind DNS Server in Chroot Jail on CentOS 7
1. Install Bind Chroot DNS server :
# yum install bind-chroot -y
2. To enable the named-chroot service, first check if the named service is running by issuing the following command:
# systemctl status named
If it is running, it must be disabled.
To disable named, issue the following commands as root:
# systemctl stop named
# systemctl disable named
3. Initialize the /var/named/chroot environment by running:
# /usr/libexec/setup-named-chroot.sh /var/named/chroot on # systemctl stop named # systemctl disable named # systemctl start named-chroot # systemctl enable named-chroot ln -s '/usr/lib/systemd/system/named-chroot.service' '/etc/systemd/system/multi-user.target.wants/named-chroot.service'
The following directories are automatically mounted into the /var/named/chroot/ directory if the corresponding mount point directories underneath /var/named/chroot/ are empty:
Verify Chroot Environment :
# ll /var/named/chroot/etc total 28 -rw-r--r-- 1 root root 372 Dec 1 23:04 localtime drwxr-x--- 2 root named 4096 Nov 22 01:28 named -rw-r----- 1 root named 1705 Mar 22 2016 named.conf -rw-r--r-- 1 root named 2389 Nov 22 01:28 named.iscdlv.key -rw-r----- 1 root named 931 Jun 21 2007 named.rfc1912.zones -rw-r--r-- 1 root named 487 Jul 19 2010 named.root.key drwxr-x--- 3 root named 4096 Jan 4 22:12 pki
# ll /var/named/chroot/var/named total 32 drwxr-x--- 7 root named 4096 Jan 4 22:12 chroot drwxrwx--- 2 named named 4096 Nov 22 01:28 data drwxrwx--- 2 named named 4096 Nov 22 01:28 dynamic -rw-r----- 1 root named 2076 Jan 28 2013 named.ca -rw-r----- 1 root named 152 Dec 15 2009 named.empty -rw-r----- 1 root named 152 Jun 21 2007 named.localhost -rw-r----- 1 root named 168 Dec 15 2009 named.loopback drwxrwx--- 2 named named 4096 Nov 22 01:28 slaves
4. Create bind dns related files into chrooted directory :
# touch /var/named/chroot/var/named/data/cache_dump.db # touch /var/named/chroot/var/named/data/named_stats.txt # touch /var/named/chroot/var/named/data/named_mem_stats.txt # touch /var/named/chroot/var/named/data/named.run # mkdir /var/named/chroot/var/named/dynamic # touch /var/named/chroot/var/named/dynamic/managed-keys.bind
5. Bind lock file should be writeable, therefore set the permission to make it writable as below :
# chmod -R 777 /var/named/chroot/var/named/data # chmod -R 777 /var/named/chroot/var/named/dynamic
6. Copy /etc/named.conf chrooted bind config folder :
# cp -p /etc/named.conf /var/named/chroot/etc/named.conf
7.Configure main bind configuration in /etc/named.conf. Append the example.local zone information to the file :
# vi /var/named/chroot/etc/named.conf
Create forward and reverse zone into named.conf:
.. .. zone "example.local" { type master; file "example.local.zone"; }; zone "0.168.192.in-addr.arpa" IN { type master; file "192.168.0.zone"; }; .. ..
Full named.conf configuration :
// // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // options { listen-on port 53 { any; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; allow-query { any; }; /* - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. - If you are building a RECURSIVE (caching) DNS server, you need to enable recursion. - If your recursive DNS server has a public IP address, you MUST enable access control to limit queries to your legitimate users. Failing to do so will cause your server to become part of large scale DNS amplification attacks. Implementing BCP38 within your network would greatly reduce such attack surface */ recursion yes; dnssec-enable yes; dnssec-validation yes; dnssec-lookaside auto; /* Path to ISC DLV key */ bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic"; pid-file "/run/named/named.pid"; session-keyfile "/run/named/session.key"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; zone "." IN { type hint; file "named.ca"; }; zone "example.local" { type master; file "example.local.zone"; }; zone "0.168.192.in-addr.arpa" IN { type master; file "192.168.0.zone"; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key";
8. Create Forward and Reverse zone files for domain example.local.
a) Create Forward Zone :
# vi /var/named/chroot/var/named/example.local.zone
Add the following and save :
; ; Addresses and other host information. ; $TTL 86400 @ IN SOA example.local. hostmaster.example.local. ( 2014101901 ; Serial 43200 ; Refresh 3600 ; Retry 3600000 ; Expire 2592000 ) ; Minimum ; Define the nameservers and the mail servers IN NS ns1.example.local. IN NS ns2.example.local. IN A 192.168.0.70 IN MX 10 mx.example.local. centos7 IN A 192.168.0.70 mx IN A 192.168.0.50 ns1 IN A 192.168.0.70 ns2 IN A 192.168.0.80
b) Create Reverse Zone :
# vi /var/named/chroot/var/named/192.168.0.zone
; ; Addresses and other host information. ; $TTL 86400 @ IN SOA example.local. hostmaster.example.local. ( 2014101901 ; Serial 43200 ; Refresh 3600 ; Retry 3600000 ; Expire 2592000 ) ; Minimum 0.168.192.in-addr.arpa. IN NS centos7.example.local. 70.0.168.192.in-addr.arpa. IN PTR mx.example.local. 70.0.168.192.in-addr.arpa. IN PTR ns1.example.local. 80.0.168.192.in-addr.arpa. IN PTR ns2.example.local.
Bind dns related articles
- How to Configure Bind-Chroot Logging on CentOS 6.2
- How to Install and Configure Bind9 DNS on Ubuntu 11.10
- How to Install and Configure Bind 9 as a Caching Server on Ubuntu 11.10
Reference :
https://www.centos.org/docs/2/rhl-rg-en-7.2/ch-bind.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/ch-bind.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec-BIND.html