详解如何在 CentOS7.0 上搭建DNS 服务器
BIND也叫做NAMED,是现今互联网上使用最为广泛的DNS服务器程序。这篇文章将要讲述如何在chroot监牢中运行BIND,这样它就无法访问文件系统中除“监牢”以外的其它部分。
例如,在这篇文章中,我会将BIND的运行根目录改为/var/named/chroot/。当然,对于BIND来说,这个目录就是/(根目录)。“jail”(监牢,下同)是一个软件机制,其功能是使得某个程序无法访问规定区域之外的资源,同样也为了增强安全性(LCTT译注:chroot“监牢”,所谓“监牢”就是指通过chroot机制来更改某个进程所能看到的根目录,即将某进程限制在指定目录中,保证该进程只能对该目录及其子目录的文件进行操作,从而保证整个服务器的安全)。BindChrootDNS服务器的默认“监牢”为/var/named/chroot。
你可以按照下列步骤,在CentOS7.0上部署BindChrootDNS服务器。
1、安装BindChrootDNS服务器
[root@centos7~]#yuminstallbind-chrootbind-y
2、拷贝bind相关文件,准备bindchroot环境
[root@centos7~]#cp-R/usr/share/doc/bind-*/sample/var/named/*/var/named/chroot/var/named/
3、在bindchroot的目录中创建相关文件
[root@centos7~]#touch/var/named/chroot/var/named/data/cache_dump.db [root@centos7~]#touch/var/named/chroot/var/named/data/named_stats.txt [root@centos7~]#touch/var/named/chroot/var/named/data/named_mem_stats.txt [root@centos7~]#touch/var/named/chroot/var/named/data/named.run [root@centos7~]#mkdir/var/named/chroot/var/named/dynamic [root@centos7~]#touch/var/named/chroot/var/named/dynamic/managed-keys.bind
4、将Bind锁定文件设置为可写
[root@centos7~]#chmod-R777/var/named/chroot/var/named/data [root@centos7~]#chmod-R777/var/named/chroot/var/named/dynamic
5、将/etc/named.conf拷贝到bindchroot目录
[root@centos7~]#cp-p/etc/named.conf/var/named/chroot/etc/named.conf
6、在/etc/named.conf中对bind进行配置。
在named.conf文件尾添加example.local域信息,创建转发域(ForwardZone)与反向域(ReverseZone)(LCTT译注:这里example.local并非一个真实有效的互联网域名,而是通常用于本地测试的一个域名;如果你需要做权威DNS解析,你可以将你拥有的域名如这里所示配置解析。):
[root@centos7~]#vi/var/named/chroot/etc/named.conf
.. .. zone"example.local"{ typemaster; file"example.local.zone"; }; zone"0.168.192.in-addr.arpa"IN{ typemaster; file"192.168.0.zone"; }; .. ..
named.conf完全配置如下:
// //named.conf // //由RedHat提供,将ISCBINDnamed(8)DNS服务器 //配置为暂存域名服务器(用来做本地DNS解析). // //See/usr/share/doc/bind*/sample/forexamplenamedconfigurationfiles. // options{ listen-onport53{any;}; listen-on-v6port53{::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;}; /* -如果你要建立一个授权域名服务器服务器,那么不要开启recursion(递归)功能。 -如果你要建立一个递归DNS服务器,那么需要开启recursion功能。 -如果你的递归DNS服务器有公网IP地址,你必须开启访问控制功能, 只有那些合法用户才可以发询问.如果不这么做的话,那么你的服 服务就会受到DNS放大攻击。实现BCP38将有效抵御这类攻击。 */ recursionyes; dnssec-enableyes; dnssec-validationyes; dnssec-lookasideauto; /*PathtoISCDLVkey*/ 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{ channeldefault_debug{ file"data/named.run"; severitydynamic; }; }; zone"."IN{ typehint; file"named.ca"; }; zone"example.local"{ typemaster; file"example.local.zone"; }; zone"0.168.192.in-addr.arpa"IN{ typemaster; file"192.168.0.zone"; }; include"/etc/named.rfc1912.zones"; include"/etc/named.root.key";
7、为example.local域名创建转发域与反向域文件
a)创建转发域
[root@centos7~]#vi/var/named/chroot/var/named/example.local.zone
添加如下内容并保存:
; ;Addressesandotherhostinformation. ; $TTL86400 @INSOAexample.local.hostmaster.example.local.( 2014101901;Serial 43200;Refresh 3600;Retry 3600000;Expire 2592000);Minimum ;Definethenameserversandthemailservers INNSns1.example.local. INNSns2.example.local. INA192.168.0.70 INMX10mx.example.local. centos7INA192.168.0.70 mxINA192.168.0.50 ns1INA192.168.0.70 ns2INA192.168.0.80
b)创建反向域
[root@centos7~]#vi/var/named/chroot/var/named/192.168.0.zone
; ;Addressesandotherhostinformation. ; $TTL86400 @INSOAexample.local.hostmaster.example.local.( 2014101901;Serial 43200;Refresh 3600;Retry 3600000;Expire 2592000);Minimum 0.168.192.in-addr.arpa.INNScentos7.example.local. 70.0.168.192.in-addr.arpa.INPTRmx.example.local. 70.0.168.192.in-addr.arpa.INPTRns1.example.local. 80.0.168.192.in-addr.arpa.INPTRns2.example.local.。
8、开机自启动bind-chroot服务
[root@centos7~]#/usr/libexec/setup-named-chroot.sh/var/named/chrooton [root@centos7~]#systemctlstopnamed [root@centos7~]#systemctldisablenamed [root@centos7~]#systemctlstartnamed-chroot [root@centos7~]#systemctlenablenamed-chroot ln-s'/usr/lib/systemd/system/named-chroot.service''/etc/systemd/system/multi-user.target.wants/named-chroot.s
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。