周围环境:
系统版本号:VBOX虚拟机centos6.0。
本机内网IP 192.168.2.198。
一、安装软件bind。
1.显示bind相关的软件包。
[root@localhost ~]# yum list bind*
bind.i686
bind-chroot.i686
bind-devel.i686
bind-dyndb-ldap.i686
bind-libs.i686
bind-sdb.i686
bind-utils.i686
2.安装必要包。主要安装三个软件包,其它的眼下没有必要安装。
bind成功安装后server是named。
[root@service ~]# yum install bind bind-libs bind-utils -y
3.查看bind安装产生的文件。主要用到两个文件。例如以下:
[root@localhost ~]# rpm -ql bind | less
/etc/NetworkManager/dispatcher.d/13-named
/etc/logrotate.d/named
/etc/named
/etc/named.conf----------------主配置文件
/etc/named.iscdlv.key
/etc/named.rfc1912.zones-------zone配置文件,include到主配置文件
/etc/named.root.key
/etc/portreserve/named
/etc/rc.d/init.d/named
/etc/rndc.conf
/etc/rndc.key
/etc/sysconfig/named
....非常多行....
二、配置DNS缓存server
1.打开/etc/named.conf文件配置改动options配置块内下面选项:
listen-on port 53 { 127.0.0.1; }; 改为 listen-on port 53 { 127.0.0.1; 192.168.2.198;}; //192.168.2.198是我的内网IP,依据自己情况改动。
#listen-on-v6 port 53 { ::1; }; //凝视掉,假设不用的话。
allow-query { localhost; }; 改为 allow-query { any; };
保存退出;
2.打开配置/etc/named.rfc1912.zones, 即主配置文件named.conf底部include进来的zone文件。
凝视掉bind自己主动生成的除下面zone块,也就是除了下面两块意外的都凝视掉:
zone "localhost" IN { //正向解析配置
type master;
file "named.localhost"; //文件相对于/var/named/文件夹
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN { //反向解析配置
type master;
file "named.loopback"; //文件相对于/var/named/文件夹
allow-update { none; };
};
3.配置正向解析文件
[root@localhost named]# vim /var/named/named.localhost
填写下面内容:
$TTL 1D
@ IN SOA localhost. root.localhost. (
201406251006 ; serial //序列号,随便写我一般写成单签日期时间
1D ; refresh //命令slave多久进行一次主动更新。
1H ; retry //假设到了refresh的时间,可是slave却无法连接master时,那么多久之后,slave会再次的主动尝试与主机连线。
1W ; expire //假设slave一直无法与master连接上,那么经过多久的时间后,则命令slave不要在连接master了。
3H ) ; minimum //没有指定生存期的数据,能够保存在数据库中的时间。及TTL
IN NS localhost.
IN A 127.0.0.1
4.配置反向解析文件,实际上就是把正向解析的配置文件复制一份。然后把里面的A记录反过来写“A”写成“PTR”
[root@localhost named]# vim /var/named/named.loopback
填写例如以下内容:
$TTL 1D
@ IN SOA localhost. root.localhost. (
201406251006 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS localhost.
IN PTR localhost.
5.改动named的相关文件属组为named
[root@localhost named]# chown :named /var/named/named*
6.检查配置文件。相关命令named-checkconf、named-checkzone
[root@localhost named]# named-checkconf [/etc/named.conf] //检查主配置文件,假设没有输出错误信息表示正常。
[root@localhost named]# named-checkzone "localhost" /var/named/named.localhost //检查正向解析配置
zone localhost/IN: loaded serial 20140625
OK
[root@localhost named]# named-checkzone "1.0.0.127.in-addr.arpa" /var/named/named.loopback //检查反向解析配置
zone 1.0.0.127.in-addr.arpa/IN: loaded serial 20140625
OK
7.启动named服务
[root@localhost named]# service named start //或者用/etc/init.d/named start启动
启动 named: [确定]
[root@localhost named]# service named status //查看服务执行状态
version: 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1
CPUs found: 1
worker threads: 1
number of zones: 18
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/0/1000
tcp clients: 0/100
server is up and running
named (pid 2144) 正在执行...
8.測试NDS
a.使用命令dig測试
[root@localhost named]# dig -t A localhost @127.0.0.1 //后面@127.0.0.1表示用本机解析,假设不想每次都写改动/etc/resolv.conf文件,加入nameserver 127.0.0.1
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t A localhost @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58945
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;localhost. IN
A
;; ANSWER SECTION:
localhost. 86400
IN A
127.0.0.1
;; AUTHORITY SECTION:
localhost. 86400
IN NS
localhost.
;; Query time: 3 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Jun 25 10:25:28 2014
;; MSG SIZE rcvd: 57
[root@localhost named]# dig -t NS localhost @127.0.0.1
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS localhost @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36123
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;localhost. IN
NS
;; ANSWER SECTION:
localhost. 86400
IN NS
localhost.
;; ADDITIONAL SECTION:
localhost. 86400
IN A
127.0.0.1
;; Query time: 2 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Jun 25 10:29:55 2014
;; MSG SIZE rcvd: 57
b.使用nslookup命令測试
[root@localhost named]# nslookup
> server 127.0.0.1
Default server: 127.0.0.1
Address: 127.0.0.1#53
> set q=A
> localhost
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: localhost
Address: 127.0.0.1
> set q=NS
> localhost
Server: 127.0.0.1
Address: 127.0.0.1#53
localhost nameserver = localhost.
>exit
三、配置DNS主域名解析server。如果域名是itxingzhe.com
1.打开编辑/etc/named.rfc1912.zones文件。加入例如以下内容。
[root@localhost etc]# vim /etc/named.rfc1912.zones
zone "itxingzhe.com" IN { //正向解析
type master;
file "named.itxingzhe.com.zone";
allow-update { none; };
};
zone "2.168.192.in-addr.arpa" IN { //反向解析,注意IP写法是反过来的网段。
type master;
file "named.2.168.192.arpa";
allow-update { none; };
};
2.到/var/named文件夹下创建正/反向解析配置文件。
a.正向解析配置
[root@localhost named]# vim /var/named/named.itxingzhe.com.zone
$TTL 1D
@ IN SOA ns1.itxingzhe.com. root.itxingzhe.com. (
20140625 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS ns1.itxingzhe.com.
IN A 192.168.2.198
www.itxingzhe.com. IN A 192.168.2.198
ftp.itxingzhe.com. IN A 192.168.2.198
//其它的域名一次类推
b.反向解析配置
[root@localhost named]# vim /var/named/named.2.168.192.arpa
$TTL 1D
@ IN SOA ns1.itxingzhe.com. root.itxingzhe.com. (
20140625 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS ns1.itxingzhe.com.
198 IN PTR ns1.itxingzhe.com.
198 IN PTR www.itxingzhe.com.
c.改动配置文件属组为named
[root@localhost named]# chown :named /var/named/named.2.168.192.arpa /var/named/named.itxingzhe.com.zone
//这样也能够
[root@localhost named]# chown :named /var/named/named*
3.检查配置文件
參考以上“二、6.检查配置文件”。
[root@localhost named]# named-checkconf
[root@localhost named]# named-checkzone "itxingzhe.com" /var/named/named.itxingzhe.com.zone
zone itxingzhe.com/IN: loaded serial 20140625
OK
[root@localhost named]# named-checkzone "named.2.168.192.arpa" /var/named/named.2.168.192.arpa
zone named.2.168.192.arpa/IN: loaded serial 20140625
OK
4.重新启动named服务或又一次载入配置文件
[root@localhost named]# service named restart
停止 named:. [确定]
启动 named: [确定]
或
[root@localhost named]# /etc/init.d/named reload
又一次加载named: [确定]
5.測试DNS
參考以上“二、8.測试DNS”。
[root@localhost named]# dig -t A www.itxingzhe.com @192.168.2.198//測试A记录
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t A www.itxingzhe.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62759
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;www.itxingzhe.com. IN
A
;; ANSWER SECTION:
www.itxingzhe.com. 86400
IN A
192.168.2.198
;; AUTHORITY SECTION:
itxingzhe.com. 86400
IN NS
ns1.itxingzhe.com.
;; ADDITIONAL SECTION:
ns1.itxingzhe.com. 86400
IN A
192.168.2.198
;; Query time: 3 msec
;; SERVER: 192.168.2.198#53(192.168.2.198)
;; WHEN: Wed Jun 25 11:24:20 2014
;; MSG SIZE rcvd: 85
[root@localhost named]# dig -t NS itxingzhe.com @192.168.2.198 //測试NS记录,注意这里的域名是不带www的
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t NS itxingzhe.com @192.168.2.198
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35904
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;itxingzhe.com. IN
NS
;; ANSWER SECTION:
itxingzhe.com. 86400
IN NS
ns1.itxingzhe.com.
;; ADDITIONAL SECTION:
ns1.itxingzhe.com. 86400
IN A
192.168.2.198
;; Query time: 3 msec
;; SERVER: 192.168.2.198#53(192.168.2.198)
;; WHEN: Wed Jun 25 11:25:01 2014
;; MSG SIZE rcvd: 65
[root@localhost named]# dig -x 192.168.2.198 //反向解析结果
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -x 192.168.2.198
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65411
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;198.2.168.192.in-addr.arpa. IN
PTR
;; ANSWER SECTION:
198.2.168.192.in-addr.arpa. 86400 IN
PTR ns1.itxingzhe.com.
198.2.168.192.in-addr.arpa. 86400 IN
PTR www.itxingzhe.com.
;; AUTHORITY SECTION:
2.168.192.in-addr.arpa. 86400
IN NS
ns1.itxingzhe.com.
;; ADDITIONAL SECTION:
ns1.itxingzhe.com. 86400
IN A
192.168.2.198
;; Query time: 5 msec
;; SERVER: 192.168.2.198#53(192.168.2.198)
;; WHEN: Wed Jun 25 11:26:12 2014
;; MSG SIZE rcvd: 123
四、DNS从server配置。如果从serverIP是192.168.2.199
1.安装bind软件。
2.配置localhost的zone配置(或者直接copy主DNSserver上的localhost配置文件)。參考(二、配置DNS缓存server);
3.配置vim /etc/named.rfc1912.zones加入例如以下内容:
zone "itxingzhe.com" IN { //正向解析从server
type slave;
master {192.168.2.198;};
file "slaves/named.itxingzhe.com.zone";
};
zone "2.168.192.in-addr-arpa" IN { //反向解析从server
type slave;
master {192.168.2.198;};
file "slaves/named.2.168.192.arpa";
};
配置文件会自己主动从主DNSserver同步过来。不用手动配置。
4.重新启动named服务;
5.ll slaves/查看数据是否同步过来。
注意:selinux会从影响server变速箱。请关闭selinux。
命令setenforce 0
版权声明:本文博主原创文章。博客,未经同意不得转载。