BIND的进阶二:视图,日志,转发,子域的授权

时间:2023-02-05 06:31:38

实验分为4部分组成:

1:DNS的转发   2:DNS日志     3:子域的授权

4:智能DNS的简单配置根据网段来分配不同的ip地址

一:DNS的转发: 转发方式有两种:only (直接把客户端请求的内容通通的发送给转发主机,自己做任何事情) first (先转发,要是没有自己再去解析)

  vim  /etc/named.conf       \\\\ 在从服务做转发,转发可以定义在全局或者自己定义的区域  

   options {
directory "/var/named";
forward first; \\转发的方式,先转发给192.168.50.128
forwarders {192.168.50.128; }; \\要是请求的内容没有对方也没有的话,再自己一层一层的迭代
}; zone "." IN {
type hint;
file "named.ca";
}; zone "iccso.com" IN {
type slave;
file "slaves/iccso.com.zone";
masters {192.168.50.128; };
allow-transfer {none; };
}; zone "50.168.192.in-addr.arpa" IN {
type slave;
file "slaves/192.168.50.zone";
masters {192.168.50.128; };
allow-transfer {none; };
};

二:DNS的日志

在讲述 logging 语句的语法之前,先要熟悉一些常用术语术语 含义

channel(通道) 日志输出方式,如:syslog、文本文件、标准错误输出或 /dev/null
category(类别) 日志的消息类别,如:查询消息或动态更新消息等
module(模块) 产生消息的来源模块名称
facility(设备) syslog 设备名
severity(严重性) 消息的严重性等级

channel:定义日志的格式有2种方式

一种是由系统的syslog来帮忙继续 保存文件为/var/log/message

一种是自定义的file来记录

[print-time boolean;]            // 是否在消息中添加时间前缀,仅用于 file 日志
                        [print-severity boolean;]        // 是否在消息中添加消息严重性前缀
                       [print-category boolean;]        // 是否在消息中添加消息类别名前缀

category :规定了日志的来源有是什么,还有保存的文件名字叫什么

client 处理客户端请求。
config 配置文件分析和处理。
database 同BIND内部数据库相关的消息,用来存储区数据和缓存记录。
default 匹配所有未明确指定通道的类别。
dnssec 处理 DNSSEC 签名的响应。
general 包括所有未明确分类的 BIND 消息。
lame-servers 发现错误授权,即残缺服务器。
network 网络操作。
notify 区更新通知消息。
queries 查询日志
resolver 名字解析,包括对来自解析器的递归查询信息。
security 批准/非批准的请求。
update 动态更新事件。
xfer-in 从远程名字服务器到本地名字服务器的区传送。
xfer-out 从本地名字服务器到远程名字服务器的区传送。

severity 语句用于指定消息的严重性等级, log_severity 的取值为(按照严重性递减的顺序):

critical
error
warning
notice
info
debug [ level ]
dynamic 是一个特殊的值,它匹配服务器当前的调试级别

配置主配置文件:

   vim /etc/named.conf  

   options {
directory "/var/named";
notify yes;
querylog yes; \\要是单独只有这个选项的话会把日志自动记录在 /var/log/message
}; logging {
9 channel querylog {
10 file "/var/log/named/query.log" versions 5 size 10M;
severity dynamic;
12 print-time yes;
print-severity yes;}; category queries {querylog;};
};
17
zone "." IN {
type hint;
file "named.ca";
}; zone "iccso.com" IN {
type master;
file "iccso.com.zone";
allow-transfer {192.168.50.228; };
}; zone "50.168.192.in-addr.arpa" IN {
type master;
file "192.168.50.zone";
allow-transfer {192.168.50.228; };
};
 [root@localhost ~]# dig -t A mail.iccso.com

 ; <<>> DiG 9.7.-P2-RedHat-9.7.-.P2.el6 <<>> -t A mail.iccso.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id:
;; flags: qr aa rd ra; QUERY: , ANSWER: , AUTHORITY: , ADDITIONAL: ;; QUESTION SECTION:
;mail.iccso.com. IN A ;; ANSWER SECTION:
mail.iccso.com. IN A 192.168.50.129 ;; AUTHORITY SECTION:
iccso.com. IN NS ns1.iccso.com.
iccso.com. IN NS ns2.iccso.com. ;; ADDITIONAL SECTION:
ns1.iccso.com. IN A 192.168.50.128
ns2.iccso.com. IN A 192.168.50.228 ;; Query time: msec
;; SERVER: 192.168.50.128#(192.168.50.128)
;; WHEN: Wed Dec ::
;; MSG SIZE rcvd: [root@localhost ~]# tail /var/log/named/query.log
-Dec- ::54.917 info: client 192.168.50.128#: query: 128.50.168.192.in-addr.arpa IN PTR + (192.168.50.128)
-Dec- ::53.055 info: client 192.168.50.128#: query: 128.50.168.192.in-addr.arpa IN PTR + (192.168.50.128)
-Dec- ::56.917 info: client 192.168.50.128#: query: mail.iccso.com IN A + (192.168.50.128)
[root@localhost ~]#

三、子域的授权

所谓的子域就是在我们申请域名下再建立一个域名 申请:iccso.com.   我们在申请的域名下:再弄出两个子域名 fin.iccso.com.   mark.iccso.com.

分两个部分完成;1:先在iccso.com的数据文件 建立两条NS记录和A记录

2:在另外一台主机安装BIND并配置对应的文件

 vim /var/named/iccso.com

 $TTL
@ IN SOA ns1 admin (
;serial
2H ;refresh
5M ;retry
1W ;expire
3H ) ;minimum
IN NS ns1.iccso.com.
fin IN NS ns1.fin.iccso.com. \\添加NS和A记录
mark IN NS ns1.fin.iccso.com.
IN NS ns2.iccso.com.
IN MX mail.iccso.com.
ns1.fin IN A 192.168.50.3
ns1.mark IN A 192.168.50.4
ns1 IN A 192.168.50.128
ns2 IN A 192.168.50.228
mail IN A 192.168.50.129
www IN A 192.168.50.128
~
 vim /etc/named.conf

 options {
directory "/var/named";
notify yes;
querylog yes;
allow-query {any; }; \\是否允许查询,默认是开始的,在{}里面我们可以自己定义,可以允许可以查询的网段
recursion yes; \\eg:allow-query {172.16.10.0/24; };
}; \\recursion 是否允许给客户端递归,定义和allow-query一样 logging {
channel querylog {
file "/var/log/named/query.log" versions size 10M;
severity dynamic;
print-time yes;
print-severity yes;}; category queries {querylog;};
}; zone "." IN {
type hint;
file "named.ca";
}; zone "iccso.com" IN {
type master;
file "iccso.com.zone";
allow-transfer {192.168.50.228; };
};

 在子域配置如下:子域ip:192.168.50.3            

 vim /var/named.conf

 options {
directory "/var/named";
forward first; //设置转发 这样我们就可以解析iccso.com域里面的数据了
forwarders {192.168.50.128; };
}; zone "." IN {
type hint;
file "named.ca";
}; zone "fin.iccso.com" IN {
type master;
file "fin.iccso.com.zone";
}; 
 vim /var/named/fin.iccso.com

 $TTL
@ IN SOA ns1 admin (
;serial
2H ;refresh
5M ;retry
1W ;expire
3H ) ;minimum
IN NS ns1.fin.iccso.com.
ns1 IN A 192.168.50.3
www IN A 192.168.50.3
~
 1 [root@localhost redhat]# dig -t NS iccso.com       \\\在我们进行测试的时候可能在日志可以看见查询请求,但是就是没有显示出来
\\有可能是防火墙挡住 关闭防火墙:server iptables stop
; <<>> DiG 9.7.-P2-RedHat-9.7.-.P2.el6 <<>> -t NS iccso.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id:
;; flags: qr rd ra; QUERY: , ANSWER: , AUTHORITY: , ADDITIONAL: ;; QUESTION SECTION:
;iccso.com. IN NS ;; ANSWER SECTION:
iccso.com. IN NS ns1.iccso.com. ;; ADDITIONAL SECTION:
ns1.iccso.com. IN A 192.168.50.128 ;; Query time: msec
;; SERVER: 192.168.50.3#(192.168.50.3)
;; WHEN: Wed Dec ::
;; MSG SIZE rcvd: [root@localhost redhat]# dig -t A www.fin.iccso.com ; <<>> DiG 9.7.-P2-RedHat-9.7.-.P2.el6 <<>> -t A www.fin.iccso.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id:
;; flags: qr aa rd ra; QUERY: , ANSWER: , AUTHORITY: , ADDITIONAL: ;; QUESTION SECTION:
;www.fin.iccso.com. IN A ;; ANSWER SECTION:
www.fin.iccso.com. IN A 192.168.50.3 ;; AUTHORITY SECTION:
fin.iccso.com. IN NS ns1.fin.iccso.com. ;; ADDITIONAL SECTION:
ns1.fin.iccso.com. IN A 192.168.50.3 ;; Query time: msec
;; SERVER: 192.168.50.3#(192.168.50.3)
;; WHEN: Wed Dec ::
;; MSG SIZE rcvd:

四 、智能的DNS-->eg:我们在访问淘宝的时候,淘宝的服务会自动的判断我们对应的区域,而分配一个离我们最近的服务ip地址,不同的ip地址

指向同一个域名主机:www.taobao.com

我们引入了视 1 vim /etc/named.conf  3 options {

         directory       "/var/named";
querylog yes;
allow-query {any; };
recursion yes;
}; View "192.168.50-segment" {
match-clients {192.168.50.0/24; }; \\在192.168.50网络时是接入时自动给对应的数据文件
zone "." IN {
type hint;
file "named.ca";
}; zone "iccso.com" IN {
type master;
file "50.iccso.com.zone"; \\数据文件位置
allow-transfer {192.168.50.228
};
}; view "192.168.156-segment" {
match-clients {192.168.156.0/; };
zone "." IN {
type hint;
file "named.ca";
}; zone "iccso.com" IN {
type master;
file "iccso.com.zone";
allow-transfer {192.168.50.228; };
};
};
 vim /var/named/.iccso.com.zone

 $TTL
@ IN SOA ns1 admin (
;serial
2H ;refresh
5M ;retry
1W ;expire
3H ) ;minimum
IN NS ns1.iccso.com.
fin IN NS ns1.fin.iccso.com.
mark IN NS ns1.fin.iccso.com.
IN NS ns2.iccso.com.
IN MX mail.iccso.com.
ns1.fin IN A 192.168.50.3
ns1.mark IN A 192.168.50.4
ns1 IN A 192.168.50.128
ns2 IN A 192.168.50.228
mail IN A 192.168.50.129
www IN A 192.168.50.128
~
~
~
 vim /var/named/iccso.com.zone 

 $TTL
@ IN SOA ns1 admin (
;serial
2H ;refresh
5M ;retry
1W ;expire
3H ) ;minimum
IN NS ns1.iccso.com.
fin IN NS ns1.fin.iccso.com.
mark IN NS ns1.fin.iccso.com.
IN NS ns2.iccso.com.
IN MX mail.iccso.com.
ns1.fin IN A 192.168.50.3
ns1.mark IN A 192.168.50.4
ns1 IN A 192.168.50.128
ns2 IN A 192.168.50.228
mail IN A 192.168.50.129
www IN A 192.168.156.128
~
~
~