默认安装好了之后,是没有配置文件named.conf以及一些DNS记录数据库的 ,都要我们自己来创建.bind用named程序来启动加载配置文件(named.conf)中的数据库文件的,我们必须手动的创建.
1.创建named.conf文件
#vi /usr/local/bind/etc/named.conf
#global setting //全局参数
options {
directory "/var/namedb"; //指定dns数据记录的目录
pid-file "/var/namedb/run/pid-file";
};
#field setting //自己添加的解析域
zone "." { //根域
type hint; //类型
file "named.ca"; //数据记录文件,即/var/namedb/named.ca
};
zone "localhost" IN { //本地域
type master;
file "localhost.zone";
allow-update { none; };
};
zone "deng.com" in { //自己创建的deng.com域
type master;
file "deng.com.zone";
};
zone "lulu.com" in { //自己创建的lulu.com域
type master;
file "lulu.com.zone";
};
#unfield 反向域
zone "0.168.192.in-addr.arpa" { //192.168.0这个网络的反向解析
type master;
file "192.168.0.zone";
};
zone "0.0.127.in-addr.arpa" IN { //本地反身解析域
type master;
file "named.local";
allow-update { none; };
};
在创建过程中,,应注意每条指令后都有“;”来结尾,{ }前后都应该有空格的,最好用自己能很好辩认的名字来创建,,比如:
zone "dengtining.com" in {
type master;
file "dengtining.com.zone";
} ;
2.下面就要创建根域的记录文件了
[root@server2 bind-9.3.2-P1]# vi /etc/resolv.conf
nameserver 211.98.4.1
//先把自己的DNS服务器IP设置一个可用的
[root@server2 /]# dig -t ns . -t类型 ns 指域 .指根域 此指令的作用是查询根域
; <<>> DiG 9.3.2-P1 <<>> -t ns .
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1004
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 3
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 500914 IN NS F.ROOT-SERVERS.NET.
. 500914 IN NS G.ROOT-SERVERS.NET.
. 500914 IN NS H.ROOT-SERVERS.NET.
. 500914 IN NS I.ROOT-SERVERS.NET.
. 500914 IN NS J.ROOT-SERVERS.NET.
. 500914 IN NS K.ROOT-SERVERS.NET.
. 500914 IN NS L.ROOT-SERVERS.NET.
. 500914 IN NS M.ROOT-SERVERS.NET.
. 500914 IN NS A.ROOT-SERVERS.NET.
. 500914 IN NS B.ROOT-SERVERS.NET.
. 500914 IN NS C.ROOT-SERVERS.NET.
. 500914 IN NS D.ROOT-SERVERS.NET.
. 500914 IN NS E.ROOT-SERVERS.NET.
;; ADDITIONAL SECTION:
A.ROOT-SERVERS.NET. 587331 IN A 198.41.0.4
C.ROOT-SERVERS.NET. 587538 IN A 192.33.4.12
J.ROOT-SERVERS.NET. 587538 IN A 192.58.128.30
;; Query time: 580 msec
;; SERVER: 211.98.4.1#53(211.98.4.1)
;; WHEN: Sat Jan 20 19:46:59 2007
;; MSG SIZE rcvd: 276
我们任选一个ip作为我们的DNS服务器的IP
[root@server2 /]# echo "nameserver 192.58.128.30" >/etc/resolv.conf
[root@server2 /]# cat /etc/resolv.conf
nameserver 192.58.128.30
[root@server2 /]# dig -t ns . 这就可以得到全部13个根域的IP了,我们重定向到named.ca文件中去
[root@server2 /]# dig -t ns . >/var/namedb/named.ca
创建完根域了
[root@server2 /]# cat /var/namedb/named.ca
; <<>> DiG 9.3.2-P1 <<>> -t ns .
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42318
;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 518400 IN NS A.ROOT-SERVERS.NET.
. 518400 IN NS H.ROOT-SERVERS.NET.
. 518400 IN NS C.ROOT-SERVERS.NET.
. 518400 IN NS G.ROOT-SERVERS.NET.
. 518400 IN NS F.ROOT-SERVERS.NET.
. 518400 IN NS B.ROOT-SERVERS.NET.
. 518400 IN NS J.ROOT-SERVERS.NET.
. 518400 IN NS K.ROOT-SERVERS.NET.
. 518400 IN NS L.ROOT-SERVERS.NET.
. 518400 IN NS M.ROOT-SERVERS.NET.
. 518400 IN NS I.ROOT-SERVERS.NET.
. 518400 IN NS E.ROOT-SERVERS.NET.
. 518400 IN NS D.ROOT-SERVERS.NET.
;; ADDITIONAL SECTION:
A.ROOT-SERVERS.NET. 3600000 IN A 198.41.0.4
H.ROOT-SERVERS.NET. 3600000 IN A 128.63.2.53
C.ROOT-SERVERS.NET. 3600000 IN A 192.33.4.12
G.ROOT-SERVERS.NET. 3600000 IN A 192.112.36.4
F.ROOT-SERVERS.NET. 3600000 IN A 192.5.5.241
B.ROOT-SERVERS.NET. 3600000 IN A 192.228.79.201
J.ROOT-SERVERS.NET. 3600000 IN A 192.58.128.30
K.ROOT-SERVERS.NET. 3600000 IN A 193.0.14.129
L.ROOT-SERVERS.NET. 3600000 IN A 198.32.64.12
M.ROOT-SERVERS.NET. 3600000 IN A 202.12.27.33
I.ROOT-SERVERS.NET. 3600000 IN A 192.36.148.17
E.ROOT-SERVERS.NET. 3600000 IN A 192.203.230.10
D.ROOT-SERVERS.NET. 3600000 IN A 128.8.10.90
;; Query time: 687 msec
;; SERVER: 192.58.128.30#53(192.58.128.30)
;; WHEN: Sat Jan 20 19:51:17 2007
;; MSG SIZE rcvd: 436
在启动之有还有一个问题,我们要用rndc来控制dns,这样必须要产生一个rndc的KEY
[root@server2 /]# rndc-confgen >/usr/local/bind/etc/rndc.conf
进入rndc.conf目录
[root@server2 etc]# tail rndc.conf | head -9 | sed 's/^#/ //' >> /user/local/bind/etc/named.conf
我们把控制的key加入到了named.conf中去了,这样我们就可以用rndc来控制dns服务器了#
用到了正则表达式
#/usr/local/bind/sbin/named -gc /usr/local/bind/etc/named.conf &
启动dns
20-Jan-2007 19:59:11.338 starting BIND 9.3.2-P1 -gc /etc/named.conf
20-Jan-2007 19:59:11.348 loading configuration from '/etc/named.conf'
[root@server2 etc]# 20-Jan-2007 19:59:11.370 no IPv6 interfaces found
20-Jan-2007 19:59:11.371 listening on IPv4 interface lo, 127.0.0.1#53
20-Jan-2007 19:59:11.373 listening on IPv4 interface eth0, 192.168.0.3#53
20-Jan-2007 19:59:11.378 command channel listening on 127.0.0.1#953
20-Jan-2007 19:59:11.379 ignoring config file logging statement due to -g option
20-Jan-2007 19:59:11.383 zone 0.0.127.in-addr.arpa/IN: loaded serial 1997022700
20-Jan-2007 19:59:11.385 zone 0.168.192.in-addr.arpa/IN: loaded serial 1997022700
20-Jan-2007 19:59:11.387 zone deng.com/IN: loaded serial 2007011812
20-Jan-2007 19:59:11.389 zone lulu.com/IN: loaded serial 2007011812
20-Jan-2007 19:59:11.390 zone localhost/IN: loaded serial 42
20-Jan-2007 19:59:11.391 running
20-Jan-2007 19:59:11.392 zone deng.com/IN: sending notifies (serial 2007011812)
20-Jan-2007 19:59:11.392 zone lulu.com/IN: sending notifies (serial 2007011812)
20-Jan-2007 19:59:11.394 client 192.168.0.3#32775: received notify for zone 'deng.com'
20-Jan-2007 19:59:11.893 client 192.168.0.3#32775: received notify for zone 'lulu.com'
[root@server2 etc]# rndc status
number of zones: 5
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0/1000
tcp clients: 0/100
server is up and running
[root@server2 etc]#
这个说明dns启动成功了,这样我们可以查询IP了,对所有域名的查询我们都直接转到根域上边了,因为我们还没有做自己的域,现在这个域名服务器只是一个空空的而已了