Fedora下DNS服务器(bind9)配置过程

发布时间:2020-07-02编辑:脚本学堂
Fedora下DNS服务器(bind9)配置过程

安装环境:
Fedora 4
bind-9.2.6.tar.gz

卸载系统自带的bind服务:

复制代码 代码如下:
# rpm -qa|grep bind
bind-libs-9.3.1-4
bind-utils-9.3.1-4
# rpm -e --nodeps bind*

一、安装BIND

1、准备工作
下载稳定的BIND服务器进行安装,下载地址:www.isc.org
wget http://ftp.isc.org/isc/bind9/9.2.6/bind-9.2.6.tar.gz
安装gcc

2 、编译安装BIND
 

复制代码 代码如下:
#tar zxvf bind-9.2.6.tar.gz
#cd bind-9.2.6
#./configure -sysconfdir=/etc/bind
#make
#makeinstall

配置BIND

二、配置根服务器

1、修改配置文件
 

复制代码 代码如下:
# vi /etc/bind/named.conf
options {
directory "/var/bind";
};
zone "." {
type hint;
file "named.ca";
};

2、建立工作目录
 

复制代码 代码如下:
#mkdir /var/bind

3、查询根DNS服务器
# dig -t NS .
; <<>> DiG 9.2.6 <<>> -t NS .
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- op QUERY, status: NOERROR, id: 28940
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 139616 IN NS G.ROOT-SERVERS.NET.
. 139616 IN NS H.ROOT-SERVERS.NET.
. 139616 IN NS I.ROOT-SERVERS.NET.
. 139616 IN NS J.ROOT-SERVERS.NET.
. 139616 IN NS K.ROOT-SERVERS.NET.
. 139616 IN NS L.ROOT-SERVERS.NET.
. 139616 IN NS M.ROOT-SERVERS.NET.
. 139616 IN NS A.ROOT-SERVERS.NET.
. 139616 IN NS B.ROOT-SERVERS.NET.
. 139616 IN NS C.ROOT-SERVERS.NET.
. 139616 IN NS D.ROOT-SERVERS.NET.
. 139616 IN NS E.ROOT-SERVERS.NET.
. 139616 IN NS F.ROOT-SERVERS.NET.

;; ADDITIONAL SECTION:
J.ROOT-SERVERS.NET. 485712 IN A 192.58.128.30
;; Query time: 51 msec
;; SERVER: 172.xx.xx.11#53(172.xx.xx.11)
;; WHEN: Tue Feb 14 01:55:39 2006
;; MSG SIZE rcvd: 244
#
#echo "nameserver 192.58.128.30" >/etc/resolv.conf
#

4、将跟记录加入到/etc/resolv.conf文件中
 

复制代码 代码如下:
#echo "nameserver 192.58.128.30" >/etc/resolv.conf

5、将跟服务器的信息导入到/var/bind/named.ca文件中
#dig -t NS . >/var/bind/named.ca
#cat /var/bind/named.ca
; <<>> DiG 9.2.6 <<>> -t NS .
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- op QUERY, status: NOERROR, id: 16471
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13

;; QUESTION SECTION:
;. IN NS

;; ANSWER SECTION:
. 517472 IN NS M.ROOT-SERVERS.NET.
. 517472 IN NS A.ROOT-SERVERS.NET.
. 517472 IN NS B.ROOT-SERVERS.NET.
. 517472 IN NS C.ROOT-SERVERS.NET.
. 517472 IN NS D.ROOT-SERVERS.NET.
. 517472 IN NS E.ROOT-SERVERS.NET.
. 517472 IN NS F.ROOT-SERVERS.NET.
. 517472 IN NS G.ROOT-SERVERS.NET.
. 517472 IN NS H.ROOT-SERVERS.NET.
. 517472 IN NS I.ROOT-SERVERS.NET.
. 517472 IN NS J.ROOT-SERVERS.NET.
. 517472 IN NS K.ROOT-SERVERS.NET.
. 517472 IN NS L.ROOT-SERVERS.NET.

;; ADDITIONAL SECTION:
A.ROOT-SERVERS.NET. 603872 IN A 198.41.0.4
B.ROOT-SERVERS.NET. 603872 IN A 192.228.79.201
C.ROOT-SERVERS.NET. 603872 IN A 192.33.4.12
D.ROOT-SERVERS.NET. 603872 IN A 128.8.10.90
E.ROOT-SERVERS.NET. 603872 IN A 192.203.230.10
F.ROOT-SERVERS.NET. 603872 IN A 192.5.5.241
G.ROOT-SERVERS.NET. 603872 IN A 192.112.36.4
H.ROOT-SERVERS.NET. 603872 IN A 128.63.2.53
I.ROOT-SERVERS.NET. 603872 IN A 192.36.148.17
J.ROOT-SERVERS.NET. 603872 IN A 192.58.128.30
K.ROOT-SERVERS.NET. 603872 IN A 193.0.14.129
L.ROOT-SERVERS.NET. 603872 IN A 198.32.64.12
M.ROOT-SERVERS.NET. 603872 IN A 202.12.27.33

;; Query time: 478 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Feb 14 12:21:35 2006
;; MSG SIZE rcvd: 436

6、配置rndc
 

复制代码 代码如下:

#rndc-confgen >/etc/bind/rndc.conf
# cat -n /etc/bind/rndc.conf
# Start of rndc.conf
  key "rndc-key" {
  algorithm hmac-md5;
  secret "OJuPxS0u/5tJ71W8ypj4fA==";
 };

 options {
  default-key "rndc-key";
  default-server 127.0.0.1;
  default-port 953;
 };
 # End of rndc.conf

 # Use with the following in named.conf, adjusting the allow list as needed:
 # key "rndc-key" {
 # algorithm hmac-md5;
 # secret "OJuPxS0u/5tJ71W8ypj4fA==";
 # };
 #
 # controls {
 # inet 127.0.0.1 port 953
 # allow { 127.0.0.1; } keys { "rndc-key"; };
 # };
 # End of named.conf

7、将rndc中的部分记录导入到/etc/bind/named.conf文件中,并修改/etc/bind/named.conf,将导入的配置前面的注释去掉。
 

复制代码 代码如下:
#tail +13 /etc/bind/rndc.conf>>/etc/bind/named.conf

8、检查并重新启动named服务,查看日志文件并检查rndc访问状态
 

复制代码 代码如下:
#ps -axu|grep named
#killall named
#ps -axu|grep named
#named
#ps -axu|grep named
#tail /var/log/messages
#rndc status
number of zones: 2
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
server is up and running

9、修改/etc/bind/named.conf,并使用host命令测试
 

复制代码 代码如下:
#echo “nameserver 127.0.0.1”>/etc/bind/named.conf
# host www.cisco.com
www.cisco.com has address 198.133.219.25

三、配置localhost区域

(一)、配置localhost的正向区域
1、修改/etc/bind/named.conf,插入如下内容
 

复制代码 代码如下:
zone "localhost" {
type master;
file "db.local";
};

2、配置/var/bind/db.local;
 

复制代码 代码如下:
$TTL 900
@ IN SOA localhost. root (
2006021401 ;serial number
1H ;refresh
15M ;retry
1W ;expire
1D ) ;TTL
IN NS @
IN A 127.0.0.1

3、测试
 

复制代码 代码如下:
# rndc reload
# host localhost
# host localhost
# dig localhost
# dig -t NS localhost
# dig -t A localhost
# rndc reload
# host localhost
localhost has address 127.0.0.1
 

# dig localhost

; <<>> DiG 9.2.6 <<>> localhost
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- op QUERY, status: NOERROR, id: 27414
;; 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: 52 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Feb 14 13:06:21 2006
;; MSG SIZE rcvd: 57

# dig -t NS localhost
; <<>> DiG 9.2.6 <<>> -t NS localhost
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- op QUERY, status: NOERROR, id: 13067
;; 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: 44 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Feb 14 13:07:54 2006
;; MSG SIZE rcvd: 57

# dig -t A localhost
; <<>> DiG 9.2.6 <<>> -t A localhost
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- op QUERY, status: NOERROR, id: 31098
;; 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: 42 msec

;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Feb 14 13:08:00 2006
;; MSG SIZE rcvd: 57