DNS

DNS服务基础
DNS功能
正向解析:根据注册的域名查找对应的IP地址
反向解析:根据ip地址查找对应的注册域名
在这里插入图片描述
域名结构:树形结构
所有域名都必须以点结尾

根域名: .

一级域名: .cn(中国) .us(美国) .jp(日本) .hk(香港)

二级域名:.com.cn .tedu.cn .net.cn .org.cn

三级域名:nb.com.cn .dc.com.cn

主机头部+注册的域名

#############################################################

bind服务器
系统服务:named
默认端口:TCP/UDP 53
主配置文件:/etc/named.conf #本机负责解析的域名
地址库文件存放路径:/var/named/ #域名的解析结果

构建DNS服务
运行时的虚拟跟环境:/var/named/chroot
1.安装bind包 安装bind-chroot包
[root@svr7 ~]# yum -y install bind #域名服务包
[root@svr7 ~]# yum -y install bind-chroot.x86_64 #提供虚拟根支持,监控binb的异常

2.修改主配置文件
[root@svr7 ~]# cp /etc/named.conf /etc/named.bak #为了安全先备份
[root@svr7 ~]# vim /etc/named.conf
options {
directory “/var/named”;
};

zone “tedu.cn” IN { #定义正向区域
type master; #设置本机为权威主DNS服务器
file “named.ca”; #地址库文件的名字
};

3.建立地址库文件tedu.cn.com

[root@svr7 ~]# cd /var/named/
[root@svr7 named]# ls
[root@svr7 named]# cp -p named.localhost  tedu.cn.zone   #-p保持权限不变
[root@svr7 named]# vim tedu.cn.zone       #所有域名必须以点结尾,当没有以点结尾时会自动补全区域内容
tedu.cn.        NS      svr7     #声明区域NDS服务器      区域.  NS  主机名.
svr7    A       192.168.4.7     #声明DNS服务器ip地址    主机名.  A    ip地址
www     A       1.1.1.1         #常规DNS正向解析
[root@svr7 named]# systemctl restart named

虚拟机B:客户端验证

[root@pc207 ~]# nslookup www.tedu.cn              #解析DNS
[root@pc207 ~]# ls /etc/resolv.conf                    #指定本机的NDS服务器地址
[root@pc207 ~]# echo nameserver 192.168.4.7  > /etc/resolv.conf
[root@pc207 ~]# nslookup apple.tedu.cn
Server:		192.168.4.7
Address:	192.168.4.7#53

Name:	apple.tedu.cn
Address: 172.168.0.1

#############################################################
多域名的DNS服务器 负责qq.com域名

[root@svr7 etc]# vim named.conf 
zone "qq.com" IN {
        type master;
        file "qq.com.zone";
};

[root@svr7 named]# cp -p tedu.cn.zone qq.com.zone
[root@svr7 named]# vim qq.com.zone 
qq.com. NS      svr7    
svr7    A       192.168.4.7
www     A       31.31.31.11
[root@svr7 named]# systemctl restart named

特殊解析记录
1.基于DNS负载均衡 分摊多个人的访问

2.泛域名解析

[root@svr7 named]# vim tedu.cn.zone 
tedu.cn.        NS      svr7
svr7    A       192.168.4.7
www     A       1.1.1.1
*       A       172.168.0.1      #  *.tedu.cn    前输入任何都可以进入

3.解析记录的别名

[root@svr7 named]# vim tedu.cn.zone 
tedu.cn.        NS      svr7
svr7    A       192.168.4.7
www     A       1.1.1.1
*       A       172.168.0.1
mail    CNAME   ftp

4.有规律的泛域名解析
pc1.tedu.cn------>192.168.10.1
pc2.tedu.cn------>192.168.10.2
pc3.tedu.cn------>192.168.10.3
pc4.tedu.cn------>192.168.10.4

pc10.tedu.cn------>192.168.10.10
内置函数:$GENERATE 制造连续范围的数字
G E N E R A T E 1 − 50 p c GENERATE 1-50 pc GENERATE150pc A 192.168.10.$

虚拟机B测试

[root@pc207 ~]# nslookup pc21.tedu.cn
Server:		192.168.4.7
Address:	192.168.4.7#53

Name:	pc21.tedu.cn
Address: 192.168.10.21

DNS资源解析记录有哪些?
正向解析记录(A记录)
DNS声明记录(NS记录)
解析记录别名(CNAME记录)
#############################################################

DNS子域授权

父域:与相同域名结尾较短的 qq.com 由虚拟机A进行解析
子域:与相同域名结尾较长的 bj.qq.com 有虚拟机B进行解析
虚拟机B,构建DNS服务器,负责解析bj.qq.com

[root@pc207 ~]# yum -y install bind bind-chroot.x86_64 
[root@pc207 ~]# cp /etc/named.conf /etc/name.bak
options {
        directory       "/var/named";
         };
zone "bj.qq.com" IN {
        type master;
        file "bj.qq.com.zone";
};     
[root@pc207 named]# nslookup www.bj.qq.com 192.168.4.207    #后面应该是域名
bj.qq.com.      NS      pc207
pc207   A       192.168.4.207
www     A       6.6.6.6

子域授权:让父域的DNS的服务器知晓子域的存在
让父域的DNS的服务器可以解析子域的域名

[root@svr7 named]# vim qq.com.zone 
qq.com. NS      ha
bj.qq.com.      NS      pc207
ha      A       192.168.4.7
www     A       31.31.31.11
pc207   A       192.168.4.207

[root@pc207 named]# nslookup www.bj.qq.com
Server:		192.168.4.7
Address:	192.168.4.7#53

Non-authoritative answer:                 #非权威解答
Name:	www.bj.qq.com
Address: 6.6.6.6

递归解析:
由客户端发出请求,首选DNS服务器接受请求,将解析结果带回过程
递归解析:

[root@svr7 named]# vim /etc/named.conf 
options {
        directory       "/var/named";
        recursion no;                   #禁止递归解析   默认开启
};
zone "tedu.cn" IN {
        type master;
        file "tedu.cn.zone";
};
zone "qq.com" IN {
        type master;
        file "qq.com.zone";
};

在这里插入图片描述

###########################################################
主机名映射文件:/etc/hosts
没有DNS服务器的前提下,解析域名,只能为本机做域名解析

[root@svr7 named]# vim /etc/hosts
192.168.4.110  www.nb.com
[root@svr7 named]# ping www.nb.com

域名解析过程中最高优先级为/etc/hosts 匹配即停止
然后再读取/etc/resolv.conf

#############################################################
缓存DNS服务器,缓存解析结果,加快解析过程

三个角色:客户端 缓存DNS服务器 真DNS服务器
虚拟机A:真DNS
1建立虚拟机C,配置ip地址192.168.4.10/24,主机名为svr10.tedu.cn

虚拟机B:缓存DNS

[root@pc207 named]# vim /etc/named.conf
options {
        directory       "/var/named";
        forwarders { 192.168.4.7; };       #转发给虚拟机A的ip地址
         };

[root@svr10 ~]# nslookup www.tedu.cn 192.168.4.207
Server:		192.168.4.207
Address:	192.168.4.207#53

Non-authoritative answer:
Name:	www.tedu.cn
Address: 1.1.1.1

虚拟机C:客户端

[root@pc207 named]# dig www.bj.qq.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.bj.qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58082
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.bj.qq.com. IN A

;; ANSWER SECTION:
www.bj.qq.com. 83986 IN A 6.6.6.6

;; AUTHORITY SECTION:
bj.qq.com. 83986 IN NS pc207.bj.qq.com.

;; ADDITIONAL SECTION:
pc207.bj.qq.com. 83986 IN A 192.168.4.207

;; Query time: 0 msec
;; SERVER: 192.168.4.7#53(192.168.4.7)
;; WHEN: 三 7月 17 15:28:10 CST 2019
;; MSG SIZE rcvd: 94

Split分离解析(视图解析)
-能够区分客户机的来源地址
-为不同类别的客户机提供不同的解析结果
-作用:为客户端就近提供服务器
在这里插入图片描述
view “other”{
match-clients{ any; };
zone “12306.cn ” IN {
…地址库文件12306.other;
}; };

[root@svr7 named]# vim /etc/named.conf
options {
directory “/var/named”;
};

view “nsd” {
match-clients{ 192.168.4.207; };
zone “tedu.cn” IN {
type master;
file “tedu.cn.zone”;
};
};
view “other” {
match-clients{ any; };
zone “tedu.cn” IN { #每一个view zone要一致
type master;
file “tedu.cn.other”;
};
};

[root@svr7 named]# vim tedu.cn.other
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
tedu.cn. NS svr7
svr7 A 192.168.4.7
www A 1.2.3.4

[root@svr7 named]# cp -p tedu.cn.zone tedu.cn.other

[root@svr7 named]# vim tedu.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
tedu.cn. NS svr7
svr7 A 192.168.4.7
www A 192.168.4.100

acl地址列表:类似于变量作用
[root@svr7 named]# vim /etc/named.conf

acl “test” {192.168.4.207; 192.168.4.255; 192.167.4.0/24; };
view “nsd” {
match-clients{ test; };
zone “tedu.cn” IN {
type master;
file “tedu.cn.zone”;
};
zone “sina.com” IN {
type master;
file “sina.com.zone”;
};
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值