一、配置前提
Bind版本:bind9.9.5
测试环境:ubuntu14.04 32位
在之前请确认etc下存在以下两个文件:bind.keys(安装完bind9后就有的文件)、rndc.conf(通过rndc命令生成的)。
二、创建配置文件
搭建DNS主要在于以下几个文件的配置,自行在etc下创建:
named.conf:设置named参数
named.ca:根服务器列表,13个
named.local:环回网络(正向)
127.0.0.zone:环回网络(逆向)
—————-以上为必配,以下需自行任意添加———-
example.com.zone:区域数据(正向)
192.168.100.zone:区域数据(逆向)
三、文件内容
named.conf
——————————-文件内容———————-
options {
directory “/opt/named/etc”;
allow-query-cache { any; };
rrset-order { order cyclic; };
pid-file “/opt/named/var/run/named.pid”;
recursion no;
max-cache-size 1024M;
};
key “rndc-key” {
algorithm hmac-md5;
secret “e8OQWP4VCAyx/Gz1NIbisA==”;
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { “rndc-key”; };
};
zone “.” IN {
check-names ignore;
type hint;
file “named.ca”;
};
zone “jxcia.com” IN { // 添加正向解析区域信息
check-names ignore;
type master ;
file “jxcia.com.zone”;
};
zone “1.168.192.in-addr.arpa” IN { // 添加反向解析区域信息
check-names ignore;
type master;
file “192.168.1.zone”;
};
zone “localhost” { //创建 localhost域
check-names ignore;
type master;
file “named.local”;
};
zone “0.0.127.in-addr.arpa”{ //localhost的反解析
check-names ignore;
type master;
file “127.0.0.zone”;
};
zone “example.com” { //创建 example.com域
check-names ignore;
type master;
file “example.com.zone”;
};
zone “100.168.192.in-addr.arpa” { //example.com的反向解析
check-names ignore;
type master;
file “192.168.100.zone”;
};
——————————-文件内容———————-
named.ca
——————————-文件内容———————-
; This file holds the information on root name servers needed to
; initialize cache of Internet domain name servers
; (e.g. reference this file in the “cache . ”
; configuration file of BIND domain name servers).
;
; This file is made available by InterNIC
; under anonymous FTP as
; file /domain/named.cache
; on server FTP.INTERNIC.NET
; -OR- RS.INTERNIC.NET
;
; last update: Jun 17, 2010
; related version of root zone: 2010061700
;
; formerly NS.INTERNIC.NET
;
. 3600000 IN NS A.ROOT-SERVERS.NET.
A.ROOT-SERVERS.NET. 3600000 A 198.41.0.4
A.ROOT-SERVERS.NET. 3600000 AAAA 2001:503:BA3E::2:30
;
; FORMERLY NS1.ISI.EDU
;
. 3600000 NS B.ROOT-SERVERS.NET.
B.ROOT-SERVERS.NET. 3600000 A 192.228.79.201
;
; FORMERLY C.PSI.NET
;
. 3600000 NS C.ROOT-SERVERS.NET.
C.ROOT-SERVERS.NET. 3600000 A 192.33.4.12
;
; FORMERLY TERP.UMD.EDU
;
. 3600000 NS D.ROOT-SERVERS.NET.
D.ROOT-SERVERS.NET. 3600000 A 128.8.10.90
;
; FORMERLY NS.NASA.GOV
;
. 3600000 NS E.ROOT-SERVERS.NET.
E.ROOT-SERVERS.NET. 3600000 A 192.203.230.10
;
; FORMERLY NS.ISC.ORG
;
. 3600000 NS F.ROOT-SERVERS.NET.
F.ROOT-SERVERS.NET. 3600000 A 192.5.5.241
F.ROOT-SERVERS.NET. 3600000 AAAA 2001:500:2F::F
;
; FORMERLY NS.NIC.DDN.MIL
;
. 3600000 NS G.ROOT-SERVERS.NET.
G.ROOT-SERVERS.NET. 3600000 A 192.112.36.4
;
; FORMERLY AOS.ARL.ARMY.MIL
;
. 3600000 NS H.ROOT-SERVERS.NET.
H.ROOT-SERVERS.NET. 3600000 A 128.63.2.53
H.ROOT-SERVERS.NET. 3600000 AAAA 2001:500:1::803F:235
;
; FORMERLY NIC.NORDU.NET
;
. 3600000 NS I.ROOT-SERVERS.NET.
I.ROOT-SERVERS.NET. 3600000 A 192.36.148.17
I.ROOT-SERVERS.NET. 3600000 AAAA 2001:7FE::53
;
; OPERATED BY VERISIGN, INC.
;
. 3600000 NS J.ROOT-SERVERS.NET.
J.ROOT-SERVERS.NET. 3600000 A 192.58.128.30
J.ROOT-SERVERS.NET. 3600000 AAAA 2001:503:C27::2:30
;
; OPERATED BY RIPE NCC
;
. 3600000 NS K.ROOT-SERVERS.NET.
K.ROOT-SERVERS.NET. 3600000 A 193.0.14.129
K.ROOT-SERVERS.NET. 3600000 AAAA 2001:7FD::1
;
; OPERATED BY ICANN
;
. 3600000 NS L.ROOT-SERVERS.NET.
L.ROOT-SERVERS.NET. 3600000 A 199.7.83.42
L.ROOT-SERVERS.NET. 3600000 AAAA 2001:500:3::42
;
; OPERATED BY WIDE
;
. 3600000 NS M.ROOT-SERVERS.NET.
M.ROOT-SERVERS.NET. 3600000 A 202.12.27.33
M.ROOT-SERVERS.NET. 3600000 AAAA 2001:DC3::35
; End of File
——————————-文件内容———————-
named.local
——————————-文件内容———————-
$TTL 1D
@ IN SOA localhost. root (
2007042801
1H
15M
1W
1D )
IN NS @
IN A 127.0.0.1
——————————-文件内容———————-
127.0.0.zone
——————————-文件内容———————-
$TTl 1D
@ IN SOA @ root.localhost. (
2007042801
1H
15M
1W
1D
)
IN NS localhost.
1 IN PTR localhost.
——————————-文件内容———————-
example.com.zone
——————————-文件内容———————-
$TTL 1D
@ IN SOA example.com. root (
2007042801
1H
15M
1W
1D )
IN NS ns.example.com.
IN MX 10 mail.example.com.
IN A 192.168.100.125
www IN A 192.168.100.125
db IN A 192.168.100.124
ns IN A 192.168.100.126
mail IN A 192.168.100.251
shop IN A 192.168.100.125
*.shop IN A 192.168.100.124
news IN CNAME www
——————————-文件内容———————-
192.168.100.zone
——————————-文件内容———————-
$TTL 1D
@ IN SOA @ root.example.com. (
2007042801
1H
15M
1W
1D
)
@ IN NS example.com.
125 IN PTR example.com.
125 IN PTR www.example.com.
124 IN PTR db.example.com.
126 IN PTR ns.example.com.
251 IN PTR mail.example.com.
——————————-文件内容———————-
编写完成后,务必
(1)使用named-checkconf检查named.conf文件,若有错误则会显示错误,没有则配置正确。
(2)使用named-checkzone检查区域文件.zone文件,若提示OK则配置正确。
以上工具均位于bind安装目录的sbin目录下。
四、测试
本虚拟机IP:172.168.0.150
1.以root身份启动named –g(调试模式使用named,仔细阅读输出,若有错会有明显提示)
2.dig www.example.com @172.28.0.150若输出中含有如下,则成功。
3.dig –x 192.168.100.125 @172.28.0.150,若输出中含有以下则配置成功。