(1)安装bind包: yum install -y bind

(2)查看配置文件: vim /etc/named.conf

(3)配置DNS

首先:在/etc/named.conf主配置文件新增一条需要解析的域名配置信息

zone "mytest.com" IN {

type master;

file "mytest.com.zone";

};

配置完该主配置文件后可以用named-checkconf命令查看文件配置是否有误

然后:添加在/var/named/目录下添加名为mytest.com.zone的配置文件,配置文件内容为:

$TTL 1D

@       IN SOA  @ admin.mytest.com. (

2016120401       ; serial

1D      ; refresh

1H      ; retry

1W      ; expire

3H )    ; minimum

IN NS   ns.mytest.com.

IN MX 5 mail.mytest.com.

mail    IN A    12.12.12.12

ns        IN A    192.168.109.131

www     IN A    192.168.109.130

bbs       IN CNAME www.mytest.com.

最后:进行DNS解析测试

dig @192.168.109.131 www.mytest.com

(如果服务器无法使用dig命令的话请先安装bind-utils包)

(4)配置反向DNS

首先:配置主配置文件/etc/named.conf

zone "109.168.192.in-addr.arpa" IN {

type master;

file "109.168.192.zone";

};

(其中:109.168.192位24位网段,后面跟上.in-addr.arpa这是固定格式)

然后:配置子配置文件/var/named/109.168.192.zone

$TTL 1D

@       IN SOA  @ admin.mytest.com. (

2016120401       ; serial

1D      ; refresh

1H      ; retry

1W      ; expire

3H )    ; minimum

IN NS   ns.mytest.com.

111     IN PTR    mail.mytest.com.

131     IN PTR    ns.mytest.com.

130     IN PTR    www.mytest.com.

(注:其中PTR是反向DNS解析的标志,注意注意)

最后:进行DNS反向解析测试

dig @192.168.109.131 -x 192.168.109.130

(-x表示反向DNS解析)

(5)DNS解析主从备份的配置(准备两台服务器:192.168.109.131(主服务器)、192.168.109.130(从服务器))

首先:配置从服务器(192.168.109.130):

配置/etc/named.conf

zone "mytest.com" IN {

type slave;

file "slaves/mytest.com.zone";

masters { 192.168.109.131; };

};

zone "109.168.192.in-addr.arpa" IN {

type slave;

file "slaves/109.168.192.zone";

masters { 192.168.109.131; };

};

(其中masters表示指定主服务器)

然后:更改主服务器(192.168.109.131)

修改主配置文件:/etc/named.conf

zone "mytest.com" IN {

type master;

file "mytest.com.zone";

notify yes;

also-notify { 192.168.109.130; };

};

zone "109.168.192.in-addr.arpa" IN {

type master;

file "109.168.192.zone";

notify yes;

also-notify { 192.168.109.130; };

};

修改子配置文件,在子配置文件中添加一个域名的解析用来测试主从的实时同步性(比如添加一个hjp.mytest.com的测试域名):

/var/named/mytest.com.zone

$TTL 1D

@       IN SOA  @ admin.mytest.com. (

2016120402       ; serial

1D      ; refresh

1H      ; retry

1W      ; expire

3H )    ; minimum

IN NS   ns.mytest.com.

IN MX 5 mail.mytest.com.

mail    IN A    12.12.12.12

ns      IN A    192.168.109.131

www     IN A    192.168.109.130

bbs     IN CNAME www.mytest.com.

hjp     IN A    121.121.121.121

最后:测试hjp.mytest.com的解析