DNS作为互联网服务的一个基础型服务,了解和掌握DNS服务的原理和配置将是每一个运维人员必备的技能,这就如同闯荡江湖的侠客不但要有的招式,还要懂的运用这些招式的心法一样,接下来我将从DNS的正反向解析、主从同步、子域授权以及Bind view这四个方面来揭开它神秘的面纱。
正反向解析:
首先,任何一台服务器要想提供服务必须要有对应的服务应用程序,安装bind
yum install -y bind bind--libs bind-utils
安装之后我们有必要认识一下bind安装之后的文件,这样有助于我们管理和配置这台服务器
1)服务脚本:/etc/rc.d/init.d/named
2)主配置文件:/etc/name.con
/etc/named.rfc1912.zones
/etc/rndc.hey
3)解析库文件:/var/named/*.ZONE
配置一台DNS服务器,就是通过修改配置文件以及定义我们需要的解析库来实现的,这里我先定义主服务器实现正反向解析
主DNS服务器:ns1.zhang.com 192.168.45.144
从DNS服务器:ns2.zhang.com 192.168.45.140
定义主配置文件:/etc/named.conf
options {
listen-on port 53 { 192.168.45.144; 127.0.0.1; };
listen-on-v6 port 53 { ::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 yes;
// dnssec-enable yes;
// dnssec-validation yes;
// dnssec-lookaside auto;
/* Path to ISC DLV key */
// bindkeys-file "/etc/named.iscdlv.key";
// managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
定义解析区域:/etc/named.rfc1912.zones
zone "zhang.com" IN {
type master;
file "zhang.com.zone";
allow-update { none; };
};
zone "45.168.192.in-addr.arpa" IN {
type master;
file "192.168.45.zone";
};
创建区域解析库文件:zhang.com.zone
$TTL 86400
$ORIGIN zhang.com.
@ IN SOA ns1.zhang.com. admin.zhang.com (
201512151943
1H
5M
7D
1D )
IN NS ns1
IN NS ns2
IN MX 10 mx1
IN MX 20 mx2
ns1 IN A 192.168.45.144
ns2 IN A 192.168.45.140
mx1 IN A 192.168.45.142
mx2 IN A 192.168.45.143
www IN A 192.168.45.141
pop IN CNAME www
smtp IN CNAME www
ftp IN CNAME www
zhang.com. IN A 192.168.45.144
* IN A 192.168.45.141
正向解析测试命令:
dig -t A zhang.com @192.168.45.144
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.4 <<>> -t A zhang.com @192.168.45.144
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54496
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;zhang.com. IN A
;; ANSWER SECTION:
zhang.com. 86400 IN A 192.168.45.144
;; AUTHORITY SECTION:
zhang.com. 86400 IN NS ns1.zhang.com.
zhang.com. 86400 IN NS ns2.zhang.com.
;; ADDITIONAL SECTION:
ns1.zhang.com. 86400 IN A 192.168.45.144
ns2.zhang.com. 86400 IN A 192.168.45.140
反向解析测试命令:
dig -x 192.168.45.141 @192.168.45.144
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.4 <<>> -x 192.168.45.141 @192.168.45.144
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56229
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;141.45.168.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
141.45.168.192.in-addr.arpa. 86400 IN PTR www.zhang.com.
;; AUTHORITY SECTION:
45.168.192.in-addr.arpa. 86400 IN NS ns1.zhang.com.
45.168.192.in-addr.arpa. 86400 IN NS ns2.zhang.com.
;; ADDITIONAL SECTION:
ns1.zhang.com. 86400 IN A 192.168.45.144
ns2.zhang.com. 86400 IN A 192.168.45.140
测试命令dig总结:
dig[-t type] name [@SERVER] [query options]
dig用于测试dns系统,因此,不会查询hosts文件进行解析;
查询选项:
+[no]trace
:跟踪解析过程
+[no]recurse
:进行递归解析
测试反向解析:
dig -x IP @SERVER
主从复制:
要实现主从同步,必须满足以下要求:
1、从服务器应该为一台独立的名称服务器;
2
、主服务器的区域解析库文件中必须有一条NS记录是指向从服务器;
3
、从服务器只需要定义区域,而无须提供解析库文件;解析库文件应该放置于/var/named/slaves/目录中;
4
、主服务器必须允许从服务器作区域传送;可使用dig -t axfr ZONE_NAME @SERVER_NAME测试主服务器是否可以做区域传送
5
、主从服务器时间应该同步,可通过ntp进行;
6
、bind程序的版本应该保持一致;否则,应该从服务器高,主服务器低;
定义主配置文件:/etc/named.conf
options {
listen-on port 53 { 192.168.45.140; 127.0.0.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 yes;
// dnssec-enable yes;
// dnssec-validation yes;
// dnssec-lookaside auto;
/* Path to ISC DLV key */
// bindkeys-file "/etc/named.iscdlv.key";
// managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
定义解析区域:/etc/named.rfc1912.zones
zone "zhang.com" IN {
type slave;
masters { 192.168.45.144; };
file "slaves/zhang.com.zone";
};
此时我们的从服务器就只需执行:
rndc reload ##重载主配置文件和区域解析库文件
从服务器就能从主服务器同步解析库文件;
执行测试命令:
dig -t A zhang.com @192.168.45.140
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.4 <<>> -t A zhang.com @192.168.45.140
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7672
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;zhang.com. IN A
;; ANSWER SECTION:
zhang.com. 86400 IN A 192.168.45.144
;; AUTHORITY SECTION:
zhang.com. 86400 IN NS ns2.zhang.com.
zhang.com. 86400 IN NS ns1.zhang.com.
;; ADDITIONAL SECTION:
ns1.zhang.com. 86400 IN A 192.168.45.144
ns2.zhang.com. 86400 IN A 192.168.45.140
子域授权:
每个域的名称服务器,都是通过上级名称服务器在解析库中进行授权,类似根域授权tld一样,那如何定义一个子域那?
首先定义主服务器解析库文件:/var/named/zhang.com.zone
$TTL 86400
$ORIGIN zhang.com.
@ IN SOA ns1.zhang.com. admin.zhang.com (
201512151943
1H
5M
7D
1D )
IN NS ns1
IN NS ns2
IN MX 10 mx1
IN MX 20 mx2
ns1 IN A 192.168.45.144
ns2 IN A 192.168.45.140
mx1 IN A 192.168.45.142
mx2 IN A 192.168.45.143
www IN A 192.168.45.141
pop IN CNAME www
smtp IN CNAME www
ftp IN CNAME www
zhang.com. IN A 192.168.45.144
* IN A 192.168.45.141
ops IN NS ns1.ops
ops IN NS ns2.ops
ns1.ops IN A 192.168.45.140
ns1.ops IN A 192.168.45.142
然后编辑子域服务器解析区域:/etc/named.rfc1912.zones
zone "ops.zhang.com" IN {
type master;
file "ops.zhang.com.zone";
};
同时一定别忘记创建解析库文件:/var/named/ops.zhang.com.zone
$TTL 1D
$ORIGIN ops.zhang.com.
@ IN SOA ns1.ops.zhang.com. admin.ops.zhang.com. (
201515160000
1H
10M
3D
1D )
IN NS ns1
IN NS ns2
ns1 IN A 192.168.45.144
ns2 IN A 192.168.45.141
www IN A 192.168.45.141
www IN A 192.168.45.141
同步主配置文件以及解析库文件:rndc reload
执行测试命令:
dig -t A www.ops.zhang.com @192.168.45.140
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.4 <<>> -t A www.ops.zhang.com @192.168.45.140
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11650
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;www.ops.zhang.com. IN A
;; ANSWER SECTION:
www.ops.zhang.com. 86400 IN A 192.168.45.141
;; AUTHORITY SECTION:
ops.zhang.com. 86400 IN NS ns1.ops.zhang.com.
ops.zhang.com. 86400 IN NS ns2.ops.zhang.com.
;; ADDITIONAL SECTION:
ns1.ops.zhang.com. 86400 IN A 192.168.45.144
ns2.ops.zhang.com. 86400 IN A 192.168.45.141
bind view:
一个bind服务器可定义多个view,每个view中可定义一个或多个zone;每个view用一来匹配一组客户端;多个view内可能需要对同一个区域进行解析,但使用不同的区域解析库文件;
网友评论