五:DNS之四:自定义解析记录

阅读(1,122)

一:DNS解析记录分为很多种,有A记录是负责从域名解析到IP的,多个A记录解析到一个IP可以实现简单的负载均衡,有PTR记录是反向解析记录,将IP解析成域名的,有MX记录是解析邮件的,以下将介绍每一个记录的添加方式:

1.1:添加A记录:

1.1.1# vim /var/named/chroot/etc/weather.com.zone 

1.1.2:通过rndc重读配置文件:

1.1.3:slave进行测试是否同步完成数据:

1.1.4:将自己的DNS改成slave的ip地址,然后测试能否解析web记录:

[root@localhost ~]# host web.weather.com
web.weather.com has address 192.168.1.106 #用host解析对应两个IP
web.weather.com has address 192.168.1.105
[root@localhost ~]# nslookup  web.weather.com  #用nslookup解析也是对应两个IP
Server:		192.168.10.104
Address:	192.168.10.104#53

Name:	web.weather.com
Address: 192.168.1.105  #两个ip地址
Name:	web.weather.com
Address: 192.168.1.106

1.2:添加CNAME解析:

1.2.1:编辑zone文件:# vim /var/named/chroot/etc/weather.com.zone 

$ORIGIN .
$TTL 3600       ; 1 hour 
weather.com                  IN SOA   root.weather.com. root.weather.com. (
                                2003       ; serial 
                                900        ; refresh (15 minutes)
                                600        ; retry (10 minutes) 
                                86400      ; expire (1 day)
                                3600       ; minimum (1 hour) 
                                )
                        NS      dnsmaster.weather.com.
$ORIGIN weather.com.
dnsmaster            A         192.168.10.103
dnsalave             A         192.168.10.104
test                 A         192.168.1.105
web                  A         192.168.1.105
web                  A         192.168.1.106
my-cname             CNAME     web.weather.com.  #my-cmane是自定义的名称,分隔符要用中横线,表示my-cname.weather.com的请求都解析到www.baidu.com.,CNAME对象后面必须要用.结束
my-cname2             CNAME     www.baidu.com.  #解析到外网的域名

1.2.2:master通过rndc重读配置文件:

[root@dnsmaster ~]# rndc reload
WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf)
server reload successful

1.2.3:slave端验证是否同步成功数据:

1.2.4:测试CNAME解析:

#host命令的测试结果:

#host  my-cname.weather.com 

[root@localhost ~]# host  my-cname.weather.com
my-cname.weather.com is an alias for web.weather.com.  #解析到一个别名记录是web.weather.com
web.weather.com has address 192.168.1.106 #解析出来web.weather.com的IP地址
web.weather.com has address 192.168.1.105

#nslookup 的解析结果

# nslookup  my-cname.weather.com

Server:		192.168.10.104
Address:	192.168.10.104#53

my-cname.weather.com	canonical name = web.weather.com.
Name:	web.weather.com  #也可以解析到别名和别名的IP地址
Address: 192.168.1.105
Name:	web.weather.com
Address: 192.168.1.106

#dig的解析结果 

# dig  my-cname.weather.com 

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> my-cname.weather.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57777
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;my-cname.weather.com.		IN	A

;; ANSWER SECTION:
my-cname.weather.com.	3600	IN	CNAME	web.weather.com. #先解析出CNAME在解析CNAME的IP
web.weather.com.	3600	IN	A	192.168.1.106
web.weather.com.	3600	IN	A	192.168.1.105

;; AUTHORITY SECTION:
weather.com.		3600	IN	NS	dnsmaster.weather.com.

;; ADDITIONAL SECTION:
dnsmaster.weather.com.	3600	IN	A	192.168.10.103

;; Query time: 5 msec
;; SERVER: 192.168.10.104#53(192.168.10.104)
;; WHEN: Tue Jul 12 08:52:49 2016
;; MSG SIZE  rcvd: 128

1.3:MX记录:MX(Mail Exchanger)记录是邮件交换记录,它指向一个邮件服务器,用于电子邮件系统发邮件时根据 收信人的地址后缀来定位邮件服务器 

1.3.1:编辑zone文件:# vim /var/named/chroot/etc/weather.com.zone  

$ORIGIN .
$TTL 3600       ; 1 hour 
weather.com                  IN SOA   root.weather.com. root.weather.com. (
                                2004       ; serial 
                                900        ; refresh (15 minutes)
                                600        ; retry (10 minutes) 
                                86400      ; expire (1 day)
                                3600       ; minimum (1 hour) 
                                )
                        NS      dnsmaster.weather.com.
$ORIGIN weather.com.
dnsmaster            A         192.168.10.103
dnsalave             A         192.168.10.104
test                 A         192.168.1.105
web                  A         192.168.1.105
web                  A         192.168.1.106
my-cname             CNAME     web.weather.com.
my-cname2             CNAME     www.baidu.com.
mail                  MX 5     192.168.1.252 #5是优先级,值越小级别越高

1.3.2:通过rndc控制重读配置文件:

[root@dnsmaster ~]# rndc reload
WARNING: key file (/etc/rndc.key) exists, but using default configuration file (/etc/rndc.conf)
server reload successful

1.3.3:slave验证数据同步完成:  

1.3.4:验证能否解析MX记录:

#dig的查询结果:

# dig MX   mail.weather.com 

#host命令的查询结果:

# host mail.weather.com 192.168.10.104  #命令格式为 host 解析的记录  指定的DNS服务器

[root@localhost ~]# host mail.weather.com 192.168.10.104
Using domain server:
Name: 192.168.10.104
Address: 192.168.10.104#53
Aliases: 

mail.weather.com mail is handled by 5 192.168.1.252.weather.com.

1.4:PTR记录(反向解析)

1.4.1:编辑 /var/named/chroot/etc/view.conf  

# vim /var/named/chroot/etc/view.conf 

view "View" { #view的名称
  zone "weather.com" {
        type    master; #角色类型
        file    "weather.com.zone"; #区域文件的名称
        allow-transfer { #允许进行同步数据的从DNS
                192.168.10.104;
        };
        notify  yes; #当master文件发生变更时,从而触发从DNS进行同步
        also-notify {
                192.168.10.104;
        };
  };
        zone "168.192.in-addr.arpa" { #新添加的反向解析
                type master;
                file "168.192.zone";
                allow-transfer {
                        192.168.10.104; #允许同步数据的IP
                };
                notify yes; #通知
                also-notify { #通知谁
                        192.168.10.104;
                };
        };
};

1.4.2:编辑反向解析区域文件 /var/named/chroot/etc/168.192.zone 

# vim /var/named/chroot/etc/168.192.zone 

$TTL 3600       ; 1 hour
@                  IN SOA  dnsmaster.weather.com. root.weather.com. (
                                2004       ; serial
                                900        ; refresh (15 minutes)
                                600        ; retry (10 minutes)
                                86400      ; expire (1 day)
                                3600       ; minimum (1 hour)
                                )
                        NS      dnsmaster.weather.com.
105.10     IN      PTR     web.weather.com. #反向解析记录,对应IP地址192.168.10.205

1.4.3:更改区域文件属主属组:

# chown  named.named  /var/named/chroot/etc/168.192.zone 

1.4.4:重读配置文件:

# rndc reload

1.5:配置DNS Slave服务器同步反向解析区域文件:

1.5.1:编辑slave的view文件,指定同步反向解析区域文件:

# vim /var/named/chroot/etc/view.conf 

view "SlaveView" {
        zone "weather.com" {
             type    slave;
             masters {192.168.10.103; };
             file    "slaves/slave.weather.com.zone";
        };

        zone "168.192.in-addr.arpa" { #反向区域的名称对应master端的名称
                type slave; #类型为slave
                masters {192.168.10.103;}; #master的地址
                file "slaves/slave.168.192.zone"; #同步文件到本机后的保存路径
        };
};

1.5.2:slave端执行rndc reload:

[root@localhost etc]# rndc reload
server reload successful

1.5.3:确认区域文件同步成功:

1.5.4:测试反向解析是否生效:

# host 192.168.10.105  192.168.10.103 #host 要解析的IP DNS服务器地址


Warning: count(): Parameter must be an array or an object that implements Countable in /home/nginx/wordpress/wp-includes/class-wp-comment-query.php on line 405

发表评论

邮箱地址不会被公开。 必填项已用*标注