构建DNS服务器
- dns服务简介
DNS domain network system 域名网络解析系统
服务:named服务
默认端口:TCP/UDP 53
主要执行程序:/usr/sbin/named
运行时的虚拟根环境:/var/named/chroot/
服务器端所需的包:bind-9.9.4-29.el7.x86_64 //域名服务包 bind-chroot-9.9.4-29.el7.x86_64 //提供虚拟根支持 牢笼政策
客户机端所需要的包:bind-utils-9.9.4-61.el7.x86_64 //提供nslookup命令来查看服务器端的域名服务 - 配置文件和地址库文件
配置文件:/etc/named.conf
地址库文件:/var/named/xxx - 实验准备
准备两台主机,一台为client,客户机要配置一下域名服务器的地址,一台为server - 实验
配置文件检查命令:named-checkconf /etc/named.conf
地址库文件检查命令:named-checkzone test.com /var/named/test.com.zone
实验一:简单配置并测试一下DNS服务器-
修改named配置文件 vi /etc/named.conf
-
建立并修改地址库配置文件
注:保证named用户对地址库文件的读权限,cp -p /var/named/named.localhost /var/named/test.com.zone
(-p 保持权限不变进行拷贝)
配置文件中:所有的域名必须以点结尾。如果没有以点作为结尾,那么默认补全本地库文件负责的域名 -
检查
进入客户机,将域名服务器的解析地址配置到/etc/resolv.conf中 echo nameserver 192.168.211.12 > /etc/resolv.conf
检查是否可以访问server端 nslookup www.test.com
实验二:多区域DNS解析,即再server端配置多个区域
vi /etc/named.conf
创建test01.com.zone地址库配置文件,保证named对它的读权限 cp /var/named/test.com.zone /var/named/test01.com.zone
修改test01.com.zone中的配置内容
client端检测:
实验三:特殊解析
解释:当客户端发送请求时,服务端会根据情况来对客户端发送过来的域名进行解析。
资源解析记录类型:
NS:声明域名服务器
A: 正向解析记录
CNAME:别名解析记录
解析分类:
轮询解析:就是挨个问一下/var/named/test.com.zone地址库文件中的域名,查到就将ip地址返回过去。
泛域名解析:泛域名即匹配所有的域名
别名:
实验四:DNS主从架构,从服务器可以备份主服务器
主服务器上的配置(192.168.211.12):- 配置文件上的配置vi /etc/named.conf
地址库文件的配置: 声明从DNS服务器
检查地址库配置是否有问题namedcheckzone test.com /var/named/test.com.zone
重启一下且并不需要配置/etc/resolv.conf
从服务器上的配置:
配置配置文件 vi /etc/named.conf
地址库文件必须与主服务器同名
当重启named服务后,从服务器会自动创建test.com.zone.slave
需要将nameserver 192.168.211.15 加入到/etc/resolv.conf中
- 配置文件上的配置vi /etc/named.conf
-
如果想解析域名完全按照主服务器,则将serial前的数字0修改一下
实验五:子域授权
A虚拟机能够解析虚拟机B负责的域名(子域授权)地址库名称并不需要相同
B虚拟机上的配置:
和一般虚拟机配置一样
将nameserver 192.168.211.12写入/etc/resolv.conf
A虚拟机上的配置:
地址库配置中需要配置B中的
不需要配置/etc/resolv.conf配置文件,A会通过递归解析查询到B的域名解析内容。
总结:递归解析:客户端发送请求给首选DNS服务器,首选DNS服务器与其他DNS服务器交互,最终将解析结果带回来过程。
迭代解析:客户端发送请求给首选DNS服务器,首选DNS服务器告知下一个DNS服务器地址。
实验六:缓存服务器
在DNS服务器配置文件上配置一下即可
实验七:分离解析
能够区分客户机的来源地址,为不同类别的客户机提供不同的解析结果(IP地址),为客户端提供最近的服务器
服务器上的配置:
针对源地址定义acl列表: