本文共 15612 字,大约阅读时间需要 52 分钟。
DNS:Domain Name Service 应用层协议
C/S,53/udp, 53/tcpBIND:Bekerley Internat Name DomainISC (www.isc.org)本地名称解析配置文件:hosts/etc/hosts%WINDIR%/system32/drivers/etc/hosts93.46.8.89 www.google.com根域: .一级域名:Top Level Domain: tldcom, edu, mil, gov, net, org, int,arpa三类:组织域、国家域(.cn, .ca, .hk, .tw)、反向域二级域名,三级域名,最多127级域名ICANN(The Internet Corporation for Assigned Names and Numbers)互联网名称与数字地址分配机构,负责在全球范围内对互联网通用顶级域名(gTLD)以及国家和地区顶级域名(ccTLD)系统的管理、以及根服务器系统的管理DNS类型:递归查询迭代查询名称服务器:域内负责解析本域内的名称的主机根服务器:13组服务器解析类型:正向解析:FQDN --> IP反向解析:IP --> FQDN注意:正反向解析是两个不同的名称空间,是两棵不同的解析树一次完整的查询请求经过的流程:Client -->hosts文件 -->DNS Service Local Cache --> DNS Server(recursion) --> Server Cache --> iteration(迭代) --> 根--> 顶级域名DNS-->二级域名DNS…解析答案:肯定答案:否定答案:请求的条目不存在等原因导致无法返回结果权威答案:非权威答案:记录类型:A, AAAA, PTR, SOA, NS, CNAME, MX,
SOA:Start Of Authority,起始授权记录;一个区域解析库有且仅能有一个SOA记录,必须位于解析库的第一条记录A:internet Address,作用,FQDN --> IPAAAA: FQDN --> IPv6PTR: PoinTeR,IP --> FQDNNS: Name Server,专用于标明当前区域的DNS服务器CNAME:Canonical Name,别名记录MX: Mail eXchanger,邮件交换器#资源记录定义的格式:语法:name [TTL] IN rr_type value注意:(1) TTL可从全局继承(2) @可用于引用当前区域的名字(3) 同一个名字可以通过多条记录定义多个不同的值;此时DNS服务器会以轮询方式响应(4) 同一个值也可能有多个不同的定义名字;通过多个不同的名字指向同一个值进行定义;此仅表示通过多个不同的名字可以找到同一个主机$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 0 ; Serial #序列号,主从服务器同步更新的条件,最多4294967296(2^32) 1D ; Refresh #刷新时间,slave 会去向 master 要求数据更新的判断的时间定义 1H ; Retry #重试时间 1W ; Expire #过期时间 3H ) ; minimum NS dns1.feng.com. #省略写法,dns1.feng.com. 1D IN NS dns1.feng.com.dns1 A 192.168.1.8 #省略写法,dns1.feng.com. 1D IN A 192.168.1.8 master A 192.168.1.200 #省略写法,master.feng.com. 1D IN A 192.168.1.100$GENERATE 1-254 HOST$ A 192.168.1.$ #对应192.168.1.{1..254}的主机对应记录*.feng.com A 192.168.1.200 #泛域名解析websrv A 192.168.1.10websrv A 192.168.1.11websrv A 192.168.1.12www CNAME websrv #别名解析,实现负载均衡。
SOA数据的说明:
Serial < 2^32 = 4294967296
Refresh >= Retry 2Refresh + Retry < ExpireExpire >= Rrtry 10Expire >= 7D一般来说,如果 DNS RR 资料变更情况频繁的,那么上述的相关数值可以订定的小一些,如果 DNS RR 是很稳定的, 为了节省带宽,则可以将 Refresh 设定的较大一些 .
$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1.feng.com.dns1.feng.com. A 192.168.1.98 PTR websrv.feng.com. #省略写法, 8.1.168.192.in-addr.arpa. IN PTR websrv.feng.com.6 PTR appsrv.feng.com.100 PTR mailsrv.feng.com.
子域授权:每个域的名称服务器,都是通过其上级名称服务器在解析库进行授权,资源记录如下:
.com. IN NS ns1.com..com. IN NS ns2.com.ns1.com. IN A 2.2.2.1ns2.com. IN A 2.2.2.2
后附bind编译安装配置
yum install -y bind
文件:主配置文件:/etc/named.conf, /etc/named.rfc1912.zones, /etc/rndc.key解析库文件:/var/named/ ZONE_NAME.ZONE解析库文件必须存在named.ca文件,默认与bind安装在同一主机,且只能通过127.0.0.1连接named进程 dig [-t type] name [@SERVER][query options]
dig只用于测试dns系统,不会查询hosts文件进行解析查询选项:+[no]trace:跟踪解析过程 : dig +trace feng.com+[no]recurse:进行递归解析测试反向解析:dig -x IP = dig –t ptr reverseip.in-addr.arpa模拟区域传送:dig -t axfr ZONE_NAME @SERVERdig -t axfr feng.com @10.10.10.11dig –t axfr 100.1.10.in-addr.arpa @172.16.1.1dig -t NS . @114.114.114.114dig -t NS . @a.root-servers.net
host [-t type] name [SERVER]
host –t NS feng.com 172.16.0.1host –t soa feng.comhost –t mx feng.comhost –t axfr feng.comhost 1.2.3.4
nslookup命令: nslookup [-option][name | -] [server]
交互式模式:nslookup>server IP: 指明使用哪个DNS server进行查询set q=RR_TYPE: 指明查询的资源记录类型NAME: 要查询的名称指定的zone语句块中或者全局的options配置文件中:
Allow-update {any;};
远程主机端:
]#chmod 770 /var/named]#setsebool -P named_write_master_zones on]#nsupdate>server 192.168.1.9>zone feng.com>update add ftp.feng.com 88888 IN A 8.8.8.8>send>update delete www.feng.com A >send测试:dig ftp.feng.com @192.168.1.9在DNS服务器端会生成一个日志文件feng.com.zone.jnl]#ll /var/named/feng.com.zone.jnl]#cat /var/named/feng.com.zone将feng.com.zone的文件格式规划好了
架设好DNS服务器后,都需要进行测试,所以这里需要有客户端进行配置好。
/etc/hosts #这个是最早的 hostname 对应 IP 的档案;/etc/resolv.conf #这个重要!就是 ISP 的 DNS 服务器 IP 记录处;/etc/nsswitch.conf #这个档案则是在『决定』先要使用 /etc/hosts 还是 /etc/resolv.conf 的设定!]#vim /etc/resolv.confnameserver DNS_IP #供实验的DNSip地址,一定是第一个nameserver 8.8.8.8nameserver 223.5.5.5nameserver 223.6.6.6
rndc ---> rndc(953/tcp)
]#rndc statusversion: 9.9.4-RedHat-9.9.4-61.el7 id:8f9657aaCPUs found: 1worker threads: 1UDP listeners per interface: 1number of zones: 103debug level: 0xfers running: 0xfers deferred: 0soa queries in progress: 0query logging is OFFrecursive clients: 0/0/1000tcp clients: 0/100server is up and running
reload: 重载主配置文件和区域解析库文件
reload zonename: 重载区域解析库文件retransfer zonename: 手动启动区域传送,而不管序列号是否增加notify zonename: 重新对区域传送发通知reconfig: 重载主配置文件querylog: 开启或关闭查询日志文件/var/log/messagetrace: 递增debug一个级别trace LEVEL: 指定使用的级别notrace:将调试级别设置为 0flush:清空DNS服务器的所有缓存记录www.feng.com
正向反向DNS配置1.在服务器上进行配置/etc/named.conf
]# vim /etc/named.confoptions { listen-on port 53 { localhost; }; #允许localhost连接named进程 listen-on-v6 port 53 { ::1; }; directory "/var/named"; #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 { localhost;any; }; #允许any所有的client进行DNS解析服务 allow-transfor { none;}; #禁止任何人转发···include "/etc/named.rfc1912.zones"; #当然,zone文件也可以放在.conf文件里面。include "/etc/named.root.key";
2.配置/etc/named.rfc1912.zones文件
]# vim /etc/named.rfc1912.zones #加入两条正向反向解析的域名zone "feng.com" IN { type master; file "feng.com.zone";};zone "1.168.192.in-addr.arpa" IN { type master; file "192.168.1.zone";};
3.解析域zone文件的配置
]# touch /var/named/{feng.com.zone,192.168.1.zone} #建立两套解析域资源]# chgrp named /var/named/{feng.com.zone,192.168.1.zone} #改变文件的属组]# chmod 640 /var/named/{feng.com.zone,192.168.1.zone} #改变文件的权限]# vim /var/named/192.168.1.zone$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1.feng.com.dns1.feng.com. A 192.168.1.98 PTR websrv.feng.com.6 PTR appsrv.feng.com.100 PTR mailsrv.feng.com.]# vim /var/named/feng.com.zone$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1.feng.com.dns1 A 192.168.1.9websrv A 192.168.1.10websrv A 192.168.1.11www CNAME websrv]#systemctl start named #至此,DNS正向反向解析库配置完成,客户端使用dig即可完成DNS解析。
要点:
1、应该为一台独立的名称服务器2、主服务器的区域解析库文件中必须有一条NS记录指向从服务器3、从服务器只需要定义区域,而无须提供解析库文件;解析库文件应该放置于/var/named/slaves/目录中4、主服务器得允许从服务器作区域传送5、主从服务器时间应该同步,可通过ntp进行;6、bind程序的版本应该保持一致;否则,应该从高,主低定义从服务器的方法:#主服务器的主配置文件options中(影响全局,若只影响局部,可以在/etc/named.rfc1912.zones添加):]#vim /etc/named.conf listen-on port 53 { localhost; }; allow-query { localhost;any; }; allow-transfer { 192.168.1.8; }; #只允许slave_ip传输]#vim /etc/named.rfc1912.zoneszone "feng.com" IN { type master; file "feng.com.zone";};]#vim /var/named/feng.com.zone$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1.feng.com. NS dns2.feng.com.dns1 A 192.168.1.9dns2 A 192.168.1.8websrv A 192.168.1.10websrv A 192.168.1.11www CNAME websrv]#chmod 640 /var/named/feng.com.zone]#chgrp named /var/named/feng.com.zone]#systemctl start named #配置完毕,启动服务#从服务器:]#vim /etc/named.confoptions { listen-on port 53 { localhost; }; allow-query { localhost;any; }; allow-transfer { none;};···};]#vim /etc/named.rfc1912.zoneszone "ZONE_NAME" IN { type slave; masters { 192.168.1.9; }; file "slaves/feng.com.zone";};]#systemctl start named ]#ll /var/named/slaves/ #重启服务后立即生成配置的文件
中间DNS服务器192.168.1.8(全局/局部)
options {··· listen-on port 53 { localhost; }; allow-query { localhost;any; }; forward first|only; #first首先转发forward IP;only只转发forward IP; forwarders { 192.168.1.9;};··· dnssec-enable no; dnssec-validation no; #关闭dnssec功能中间DNS服务器(局部域名转发)zone "feng.com" IN { type forward; forward first|only; forwarders { 192.168.1.9;};};192.168.1.9的DNS正向服务器解析配置参照实验1配置即可。
有三个方法:
1.当成父域的一条记录
2.子域,本机的独立域名
3.委派给另一台主机维护子域(主要应用)
父域:192.168.1.9 www.feng.com 子域:192.168.1.8 www.bj.feng.com
]# vim /etc/named.conf listen-on port 53 { localhost; }; allow-query { localhost;any; }; dnssec-enable no; dnssec-validation no; #关闭dnssec功能···]#vim /etc/named.rfc1912.zoneszone "feng.com" IN { type master; file "feng.com.zone";};]#vim /var/named/feng.com.zone $TTL 86400@ IN SOA dns1.feng.com. admin.feng.com. (1 1D 2H 1W 3H) NS dns1.feng.com.bj NS dns2.feng.com. ##增加这条ns sh NS dns3.feng.com. dns1 A 192.168.1.9dns2 A 192.168.1.8 ##增加这条A记录dns3 A 192.168.1.7 ]#systemctl start named #配置完毕,启动服务
在子域192.168.1.8配置bj.feng.com域名即可
在子域192.168.1.7配置sh.feng.com域名即可,参照实验1即可
DNS服务器:192.168.1.9/24 ; 172.20.1.24/16
需求:
192.168.1.0/24 本地的网段访问www.feng.com的时候,DNS解析为192.168.1.10
非192.168.1.0/24 外部的网段访问www.feng.com的时候,DNS解析为192.168.1.11
注意:view语句块必须包含所有的zone,所有需要把.(root)域转移到/etc/named.rfc1912.zones。进行模块化的管理。
]#vim /etc/named.confacl bjnet { 192.168.1.0/24;};acl othernet {!192.168.1.0/24;any;};/*zone "." IN { type hint; file "named.ca";};*/view "bjnet" { match-clients {"bjnet";}; include "/etc/named.rfc1912.zones.bj";};view "othernet" { match-clients {"othernet";}; include "/etc/named.rfc1912.zones";};// include "/etc/named.rfc1912.zones"; ]#cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bj]#vim /etc/named.rfc1912.zones.bjzone "." IN { type hint; file "named.ca";};zone "feng.com" IN { type master; file "feng.com.zone.bj";};]#vim /etc/named.rfc1912.zoneszone "." IN { type hint; file "named.ca";};zone "feng.com" IN { tpye master; file "feng.com.zone";};]#vim /var/named/feng.com.zone$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1.feng.com.dns1 A 192.168.1.9websrv A 192.168.1.10www CNAME websrv]#vim /var/named/feng.com.zone.bj$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1.feng.com.dns1 A 192.168.1.9websrv A 192.168.1.11www CNAME websrv]#systemctl start named #配置好,启动服务
场景:.(root)服务器,com.服务器,feng.com服务器,www.feng.com主机,电信转发服务器,clinets
主机:centos7.4
.(root):192.168.1.1
com.:192.168.1.2
feng.com.:192.168.1.3 从:192.168.1.33 高可用
www.feng.com.: 192.168.1.4 负载均衡备用主机:192.168.1.44
DNStrans:192.168.1.5
clients:192.168.1.6
![](C:\Users\hongfeng\Desktop\network Diagram MIS.png)
1.根服务器的配置192.168.1.1
]# vim /etc/named.conf listen-on port 53 { localhost; }; allow-query { localhost;any; }; dnssec-enable no; dnssec-validation no; #关闭dnssec功能,需要委派···/*zone "." IN { tpye hint; file "named.ca";};*/]#vim /etc/named.rfc1912.zoneszone "." IN { type master; file "root.zone";};]#vim /var/named/root.zone$TTL 86400@ IN SOA dns1. admin. (1 1D 2H 1W 3H) NS dns1com NS dns2 #委派子域com.dns1 A 192.168.1.1dns2 A 192.168.1.2]#systemctl start named #配置完毕,启动服务
2.搭建区域dns服务器192.168.1.5
]# vim /etc/named.conf listen-on port 53 { localhost; }; allow-query { localhost;any; }; dnssec-enable no; dnssec-validation no; #关闭dnssec功能,需要转发···]#vim /var/named/named.ca; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3.2 <<>> +bufsize=1200 +norec @a.root-servers.net; (2 servers found);; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17380;; flags: qr aa; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 27;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 1472;; QUESTION SECTION:;. IN NS;; ANSWER SECTION:. 518400 IN NS a.root-servers.net.a.root-servers.net. 3600000 IN A 192.168.1.1 #把CDN服务器指向已经搭好的根服务器IP]#systemctl start named
3.搭建com.服务器:192.168.1.2
]# vim /etc/named.conf listen-on port 53 { localhost; }; allow-query { localhost;any; }; dnssec-enable no; dnssec-validation no; #关闭dnssec功能,需要委派]#vim /etc/named.rfc1912.zoneszone "com" IN { type master; file "com.zone"};]#vim /var/named/com.zone$TTL 86400@ IN SOA dns1.com. admin.com. (1 1D 2H 1W 3H) NS dns1feng NS dns2 #委派子域feng.com.feng NS dns3dns1 A 192.168.1.2dns2 A 192.168.1.3dns3 A 192.168.1.33
4.搭建feng.com.服务器:主:192.168.1.3 从:192.168.1.33
前面的操作类似实验1,不赘述]#vim /var/named/feng.com.zone$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1.feng.com. NS dns2.feng.com.dns1 A 192.168.1.3dns2 A 192.168.1.33websrv A 192.168.1.4websrv A 192.168.1.44www CNAME websrv
5.搭建www.feng.com主机:192.168.1.4 备:192.168.1.44
]#yum install httpd -y]#setenforce 0]#echo welcome to my website! >> /var/www/html/index.hmtml]#systemctl start httpd]#systemctl stop firewalld
6.clients访问
dig或者host命令是bind包
]#rpm -qf /usr/bin/digbind-utils-9.9.4-61.el7.x86_64]#rpm -q bind &> /dev/null || yum install -y bind]#dig www.feng.com @192.168.1.5]#host www.feng.com 192.168.1.5]#curl www.feng.com
开启dns服务,启用rndc服务
]#useradd -r -d /var/named -u 25 -s /sbin/nologin -m named]#./configrue --prefix=/app/bind]#make -j 4 && make install ]#yum groupinstall "devlopment tools"]#yum install openssl-devel -y]#vim /etc/profile.d/bind.shPATH=/app/bind/bin:/app/bind/sbin:$PATH]#vim /app/bind/etc/named.confoptions { directory "/var/named";};zone "feng.com" { type master; file "feng.com.zone";};zone "." { type hint; file "named.ca";};]#chgrp named /app/bind/etc/named.conf]#chmod 640 /app/bind/etc/named.conf]#mkdir /var/named/]#dig -t ns . @a.root-servers.net > /var/named/named.ca]#vim /var/named/feng.com.zone$TTL 1D@ IN SOA dns1.feng.com. admin.feng.com. ( 1 1D 1H 1W 3H ) NS dns1dns1 A 192.168.1.9websrv A 192.168.1.10websrv A 192.168.1.11www CNAME websrv]#named -u named -g -d 3 ]#named -u named -d 3 #dns基本配置完成,后台启用服务]#rndc-confgen > /app/bind/etc/rndc.conf]#grep '^#' /app/bind/etc/rndc.conf >> /app/bind/etc/named.conf]#vim /app/bind/etc/named.conf #去掉rndc配置的相关的#号key "rndc-key" { algorithm hmac-sha256; secret "sTvCPeQfkCmaObjPsnXXpqqryxkse4EmWUQylO4Wl5M=";};controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; };};]#killall -HUP named #重新加载配置文件,dns服务重启成功
]#cd /root/bind-9.13.0/contrib/queryperf]#./configure ]#make]#cp queryperf /app/bind/bin/ ]#vim /root/dnstest.txt www.feng.com Afeng.com NSfeng.com SOAfeng.com MX ]#cat >> /root/dnstest.txt < /root/dnstest.txt #生成大文件]#sed -i '100000,$d' /root/dnstest.txt #取前100000行]#queryperf -d /root/dnstest.txtStatistics: Parse input file: once Ended due to: reaching end of file Queries sent: 4055040 queries Queries completed: 4055040 queries Queries lost: 0 queries Queries delayed(?): 0 queries RTT max: 1.629313 sec RTT min: 0.000057 sec RTT average: 0.004647 sec RTT std deviation: 0.008495 sec RTT out of range: 0 queries Percentage completed: 100.00% Percentage lost: 0.00% Started at: Sat Jun 2 23:03:40 2018 Finished at: Sat Jun 2 23:19:26 2018 Ran for: 945.913922 seconds Queries per second: 4286.901700 qps
转载于:https://blog.51cto.com/13698281/2123494