[转帖]如何配置DNS Server(附详细实例)

发表于:2007-06-09来源:作者:点击数: 标签:
[这个贴子最后由carlous在2002/05/2409:41am编辑] 1.有关域名的说明 TCP/IP域名影响TCP/IP主机的地址翻译,即主机名到地址的转换。此外,域名也影响邮件交换,即邮件地址到邮件 服务器 的映射。 Internet上的域名通常带有后缀,但实际配置中可以不给出后缀。

[这个贴子最后由carlous在 2002/05/24 09:41am 编辑]

1. 有关域名的说明
  TCP/IP域名影响TCP/IP主机的地址翻译,即主机名到地址的转换。此外,域名也影响邮件交换,即邮件地址到邮件服务器的映射。
  Internet上的域名通常带有后缀,但实际配置中可以不给出后缀。
  域名系统包括域名服务器(DNS)和域名客户机。
  一个TCP/IP客户(如MS Windows)通常通过以下几种方式查找某个主机的地址:
  · 使用HOSTS文件,在该文件中给出名字/地址表;
  · 使用WINS协议,给出WINS服务器地址;
  · 使用DNS,这时需要给出域名服务器(DNS)地址。

2. 相关文件
  和DNS配置相关的文件包括:
  · /etc/defaultdomain
  · /etc/nsswitch.conf
  · /etc/resolv.conf
  · /etc/named.boot
  · 以及和具体域名配置的"主机"、"本地网络"、"反向"、"Cache"等四个文件。
  这里的四个文件的路径以及文件名均在文件"/etc/named.boot"中给出。
  以下的示例中,路径使用"/var/named",四个文件分别为named.hosts,named.local,named.rev和named.ca。
  以上文件权限只需root可读即可。

3. DNS具体配置说明
  (1) /etc/defaultdomain
  "/etc/defaultdomain"文件给出确省域名,该文件内容为域名名称,例如:
   so.unis
   表示缺省域名为"so.unis",以后仅使用某个主机名时,系统假设为缺省域中的主机。例如,"ping www"将被理解为"ping www.so.unis"。
  (2) /etc/nsswitch.conf
  如果使用DNS,则必须在该文件的"HOST"一项中给出"DNS"。缺省为使用文件,即"FILES",该选项可以保留。
  例如:
   # /etc/nsswitch.files:
   …
   hosts: dns files
   …
  (3) /etc/resolv.conf
  该文件给出域名和域名服务器地址。
  例如:
   ; /etc/resolv.conf file 
   domain so.unis ;域名
   nameserver 192.168.99.1 ;域名服务器地址
   ;域名服务器地址可以给出多个
  (4) /etc/named.boot
  该文件指明DNS所需具体文件的路径和文件名。
  例如:
  ; named.boot file
  directory /var/named
  ;文件所在路径,通常使用/var/named
  cache . named.ca ;dns cache file,其中点表示当前域
  primary so.unis named.hosts ;dns host file
  secondary unis 192.168.0.1 ;另一个域"unis"的DNS地址
  primary 0.0.127.in-addr.arpa named.local
  ;local dns file,127.0.0.0为本地子网
  primary 99.168.192.in-addr.arpa named.rev
  ;named rev file,本子网为192.168.99.0 

(5) /var/named/named.hosts
说明如下:
; named.hosts - dns file
;
; SOA rec
so.unis. IN SOA dns.so.unis. root.dns.so.unis. (
;SOA记录,
;dns.so.unis为DNS对应的主机
;root.dns.so.unis为主机的管理员用户为root
;以上的域、主机及用户后均需要跟上点
1998120816 ;dns序列号,可以使用年月日时
10800 ;refresh after 3 hours
10800 ;retry after 3 hour
604800 ;expire after 1 week
86400) ;minimum TTL of 1 day
so.unis. IN NS dns.so.unis.
;name server
;以下为主机/地址对应表
dns.so.unis. IN A 192.168.99.1
localhost IN A 127.0.0.1
dbserver.so.unis. IN A 192.168.99.2
www.so.unis. IN A 192.168.99.3
mail.so.unis. IN A 192.168.99.4
ftp.so.unis IN A 192.168.99.3
;mail exchange
so.unis IN MX 1 mail.so.unis.
(6) /var/named/named.local
; named.local - dns file
;
; SOA rec
0.0.127.in-addr.arpa. IN SOA dns.so.unis. root.dns.so.unis. (
1998120816 ;serial number
10800 ;refresh after 3 hours
10800 ;retry after 3 hour
604800 ;expire after 1 week
86400) ;minimum TTL of 1 day
;name server
0.0.127.in-addr.arpa. IN NS dns.so.unis.
1.0.0.127.in-addr.arpa. IN PTR localhost
(7) /var/named/named.rev
; named.rev - dns file
;
; SOA rec
99.168.192.in-addr.arpa. IN SOA dns.so.unis. root.dns.so.unis. (
19981208 ;serial number
10800 ;refresh after 3 hours
10800 ;retry after 3 hour
604800 ;expire after 1 week
86400) ;minimum TTL of 1 day
;name server
99.168.192.in-addr.arpa. IN NS dns.so.unis.
1.99.168.192.in-addr.arpa. IN PTR dns.so.unis.
( /var/named/named.ca
; named.ca - dns cache file
;
@ IN SOA dns.so.unis. root.dns.so.unis. (
1998120815 ;serial number
10800 ;refresh after 3 hours
3600 ;retry after 3 hour
604800 ;expire after 1 week
86400) ;minimum TTL of 1 day
;
dns.so.unis. 999999 IN A 192.168.99.1
99.168.192.in-addr.arpa. IN NS so.unis.
dns.so.unis. IN A 192.168.99.1

4. 配置文件示例
温州瓯海法院DNS配置:
域名为:oh.wz.zj,主子网为203.3.6.0,DNS地址为203.3.6.1,主机名为"ohfy"。
文件内容如下:
(1) /etc/defaultdomain
oh.wz.zj
(2) /etc/nsswitch.conf
#
# /etc/nsswitch.files:
#
# "hosts:" and "services:" in this file are used only if the
# /etc/netconfig file has a "-" for nametoaddr_libs of "inet" transports.

passwd: files
group: files
hosts: dns files
networks: files
protocols: files
rpc: files
ethers: files
netmasks: files 
bootparams: files
publickey: files
# At present there isn't a 'files' backend for netgroup; the system will 
# figure it out pretty quickly, and won't use netgroups at all.
netgroup: files
automount: files
aliases: files
services: files
sendmailvars: files
(3) /etc/resolv.conf
;
; /etc/resolv.conf file for dnsmaster (E450)
; written in 1998-12-8, UNIS
;

domain oh.wz.zj ;This domain name
nameserver 203.3.6.1 ;this domain name server

;nameserver 202.x.x.x ;parent dns server
(4) /etc/named.boot
;
; /etc/named.boot file for dnsmaster (E450)
; written in 1998-12-8, UNIS
;
directory /var/named
cache . named.ca ;dns cache file
primary oh.wz.zj named.hosts ;dns host file
;secondary wz.zj 202.x.x.x
primary 0.0.127.in-addr.arpa named.local ;local dns file
primary 6.3.203.in-addr.arpa named.rev ;named rev file
(5) /var/named/named.ca
;
; named.ca - dns cache file
; written in 1998-12-8, tusc
;

@ IN SOA ohfy.oh.wz.zj. root.ohfy.oh.wz.zj. (
1998120815 ;serial number
10800 ;refresh after 3 hours
3600 ; retry after 3 hour
604800 ; expire after 1 week
86400) ; minimum TTL of 1 day
;
ohfy.oh.wz.zj. 999999 IN A 203.3.6.1
;
;wz. IN NS oh.wz.
6.3.203.in-addr.arpa. IN NS oh.wz.zj.
ohfy.oh.wz.zj. IN A 203.3.6.1
(6) /var/named/named.hosts
;
; db.oh - dns file
; written in 1998-12-8, tusc
;

;
; SOA rec
oh.wz.zj. IN SOA ohfy.oh.wz.zj. root.ohfy.oh.wz.zj. (
1998120816 ;serial number
10800 ;refresh after 3 hours
10800 ; retry after 3 hour
604800 ; expire after 1 week
86400) ; minimum TTL of 1 day
;name server
oh.wz.zj. IN NS ohfy.oh.wz.zj.

;address
ohfy.oh.wz.zj. IN A 203.3.6.1
localhost IN A 127.0.0.1
dbserver.oh.wz.zj. IN A 203.3.6.1
www.oh.wz.zj. IN A 203.3.6.1
mail.oh.wz.zj. IN A 203.3.6.1
ftp IN A 203.3.6.1

;wz.zj. IN A 202.x.x.x ;parent dns server

;mail exchange
oh.wz.zj IN MX 1 mail.oh.wz.zj.
(7) /var/named/named.local
;
; named.local - dns file
; written in 1998-12-8, tusc
;

; SOA rec
0.0.127.in-addr.arpa. IN SOA ohfy.oh.wz.zj. root.ohfy.oh.wz.zj. (
1998120816 ;serial number
10800 ;refresh after 3 hours
10800 ;retry after 3 hour
604800 ;expire after 1 week
86400) ;minimum TTL of 1 day
;name server
0.0.127.in-addr.arpa. IN NS ohfy.oh.wz.zj.
1.0.0.127.in-addr.arpa. IN PTR localhost
( /var/named/named.rev
;
; oh.rev - dns file
; written in 1998-12-8, tusc
;

; SOA rec
6.3.203.in-addr.arpa. IN SOA ohfy.oh.wz.zj. root.ohfy.oh.wz.zj. (
19981208 ;serial number
10800 ;refresh after 3 hours
10800 ;retry after 3 hour
604800 ;expire after 1 week
86400) ;minimum TTL of 1 day
;name server
6.3.203.in-addr.arpa. IN NS ohfy.oh.wz.zj.
1.6.3.203.in-addr.arpa. IN PTR ohfy.oh.wz.zj.



 sunboy 回复于:2002-05-23 10:50:11
named.boot是老版本的啦,solaris2.6以下用的,solaris 2.7以上不一样了,不过,有转换不同版本的命令

 rambler 回复于:2002-05-23 11:22:45
谢谢你carlous,建议将此帖加入精华区

 rambler 回复于:2002-05-23 11:28:14
sunboy 转换命令是什么啊

 sunboy 回复于:2002-05-23 12:45:52
嗯,转换命令就是把2。6里面的named.boot转换成2。8支持的named.conf文件

 amiao 回复于:2002-05-23 13:24:52
有没新版本的呢?

 阿骁 回复于:2002-05-23 14:10:00
carlous老大,你写的DNS的配置已经是很早的版本了,应该是BIND4的版本吧!现在大多数已经不用了,现在的版本是BIND8和9了。配置文件的写法已经有很大的变化了呀!

 rambler 回复于:2002-05-23 14:51:15
楼上的,你来写个新的吧!强烈期盼!!!

 阿骁 回复于:2002-05-23 14:59:37
三少爷说要写的,但至今没有消息。。。。。。

 rambler 回复于:2002-05-23 17:01:26
很急啊,我想针对高版本的改改上面配置,不是很快吗,我不会,有人能不能改啊

 阿骁 回复于:2002-05-23 17:14:39
好吧,我晚上把最上面的配置改给你看。

 daemonix 回复于:2002-05-23 17:55:29
强烈期待~~~~

 阿骁 回复于:2002-05-23 19:50:38
[这个贴子最后由阿骁在 2002/05/23 07:54pm 编辑]

在BIND8中文件named.boot应改成named.conf,并放在/etc/目录下

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:  named.conf
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

options {
  directory "/var/named";          ;dns工作目录     
  notify yes;                      ;是否通知slave服务器域的更新
  pid-file "/var/run/named.pid";   ;dns的进程号
  allow-transfer { 202.x.x.x; };   ;只允许202.x.x.x进行域数据的传输
};

zone "." {                         ;dns根服务器的配置文件
  type hint;
  file "name.root";
};

zone "0.0.127.IN-ADDR.ARPA" {      ;本机的ip反解配置文件
  type master;
  file "named.local";
};

zone "oh.wz.zj" {                  ;oh.wz.zj域的配置文件
  type master;                     ;master表示主dns服务器
  file "named.hosts";
};

zone "6.3.203.in-addr.arpa" {
  type master;
  file "named.rev"
};

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:  named.local
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

$TTL    3600
@       IN      SOA     ohfy.oh.wz.zj.   root.ohfy.oh.wz.zj.  (
                                2001120601      ; Serial
                                10800    ; Refresh
                                10800     ; Retry
                                604800 ; Expire
                                86400   ; Minimum

                IN      NS      localhost.      ;IN表示internet类型
                IN      NS      ohfy.oh.wz.zj.  

1               IN      PTR     localhost.      

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:  named.hosts
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

$TTL    3600

$ORIGIN oh.wz.zj.
@       IN      SOA     ohfy.oh.wz.zj. root.ohfy.oh.wz.zj.  (
                                2002042401      ; Serial
                                10800    ; Refresh
                                10800     ; Retry
                                604800 ; Expire
                                86400   ; Minimum
        IN      NS      ohfy.oh.wz.zj.
        IN      MX      mail.oh.wz.zj.
        
ohfy            IN      A       203.3.6.1 
dbserver        IN      A       203.3.6.1
www             IN      A       203.3.6.1
mail            IN      A       203.3.6.1
ftp             IN      CNAME   www.oh.wz.zj.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:  named.rev
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@       IN      SOA     ohfy.oh.wz.zj. root.ohfy.oh.wz.zj.  (
                                2002042401      ; Serial
                                10800    ; Refresh
                                10800     ; Retry
                                604800 ; Expire
                                86400   ; Minimum
        IN      NS      ohfy.oh.wz.zj.

1       IN      PTR     ohfy.oh.wz.zj.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:  named.root
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

named.root 文件是DNS的根服务器地址文件,在网上就可以当到,这里就不说了。

 coolgxg 回复于:2002-05-23 20:02:17
阿骁:
    好啊好啊!
    多写点好文章出来!我们支持你!    
  
  
  

 sunboy 回复于:2002-05-23 21:29:48
建议大家到www.study-area.org这个网站去看看,台湾人写的,关于linux网络设置中的dns & bind的配置文章写得很详细!!!

 sunboy 回复于:2002-05-23 21:32:08
http://www.study-area.org/gb/?http://www.study-area.org/linux/linuxfr1.htm

 rambler 回复于:2002-05-24 11:37:02
谢谢sunboy

 carlous 回复于:2002-05-24 12:05:45
找来的sun的英文档,希望有点帮助

3.6: How to Set Up a Caching Only DNS Server

Following is a sample of how to set up a caching only name server.
This will be a name server which will cache records it looks up, but
will control no records of its own:

--start /etc/named.boot--
;
;         named.boot file for a caching only name server
;
directory     /var/named
cache         .                               named.ca
primary       0.0.127.in-addr.arpa            named.local
--end /etc/named.boot--

--start /var/named/named.local--
;
;                   Address to host mapping for 127.0.0 net
;    
;     Note: In this and all other examples, the SOA line contains
;     the following args:
;    
;    @ IN SOA controlling-machine email (serial refresh retry expire ttl)
;    
;The '@' indicates that the domain name is the same as the origin,
;as specified in the the named.boot file.
;
;The 'controlling-machine' is the machine which holds the primary
;       records for this particular domain.
;
;'email' is an e-mail address for the DNS administrator, with
;        the '@' substituted for a '.'
;
;The parentheses allow the SOA record to span more than one line.
;

@INSOA    dns.test.com. administrator.test.com. (
                  1           ; serial number 
                  10800       ; refresh after 3 hours
                  3600        ; retry after 1 hour
                  604800      ; expire after 1 week
                  86400      ; minimum TTL of 1 day

IN      NS      dns.test.com.
1               IN      PTR     localhost.
dns.test.com.   IN      A       192.1.1.1
--end /var/named/named.local--

There will also need to be a /var/named/named.ca file, which should be
retrieved as described in section 3.5.

The books listed in sections 7.4 and 7.5 give a much more in-depth
description of setting up a caching only name server.

3.7: How to Set Up a Primary DNS Server

Following is a sample of how to set up a primary DNS server.  This
will be a name server which will cache records it looks up, and also
controls records of its own. Please note that in this example we
control both the domain test.com, and a theoretical set of IP
addresses for that domain, 192.1.1.0. All DNS servers should control
both their forward and reverse address records.

--start /etc/named.boot--
;  
;         named.boot file for a primary name server
;    
directory     /var/named
cache         .                               named.ca
primary       0.0.127.in-addr.arpa            named.local
primary       test.com                        named.test
primary       1.1.192.in-addr.arpa            named.rev
--end /etc/named.boot--

--start /var/named/named.local--
[Identical to section 3.6 above]
--end /var/named/named.local--

--start /var/named/named.test--
;  
;                   Host to address mapping for test.com
;    
@IN      SOA    dns.test.com. administrator.test.com. (
1; serial number 
10800; refresh after 3 hours
3600; retry after 1 hour
604800; expire after 1 week
86400  ; minimum TTL of 1 day
                IN NS         dns.test.com.
dns.test.com.   IN A          192.1.1.1
num2.test.com.  IN A          192.1.1.2
;    there should be one A record as above for each machine in the
;    test.com domain
--end /var/named/named.test--

--start /var/named/named.rev--
;
;                   Address to Host mapping for test.com
;
@               IN       SOA    test.com. administrator.test.com. (
1; serial number 
10800 ; refresh after 3 hours
3600; retry after 1 hour
604800; expire after 1 week
86400  ;minimum TTL of 1 day
IN NS         dns.test.com.
1               IN PTR        dns.test.com.
2               IN PTR        num2.test.com.
dns.test.com.   IN A          192.1.1.1

--end /var/named/named.rev--

NOTE: there should be one PTR record as above for each machine in the
      1.1.192.in-addr.arpa domain, that is every machine whose network
      number starts with 192.1.1.

DON'T FORGET THE TRAILING "."!!!

There will also need to be a /var/named/named.ca file, which should be
retrieved as described in section 3.5.

The books listed in sections 7.4 and 7.5 give a much more in depth
description of setting up a caching only name server.

3.8: How to Set Up a Secondary DNS Server

Following is a sample of how to set up a secondary DNS server.  This
will be a name server which will cache records it looks up, and also
backs up records for a domain.  Please note that we secondary both the
domain test.com, and a theoretical set of IP addresses for that
domain, 192.1.1.0.

--start /etc/named.boot--
;
;         named.boot file for a caching only name server
;
directory     /var/named
cache         .                               named.ca
primary       0.0.127.in-addr.arpa            named.local
secondary     test.com                192.1.1.1       named.test
secondary     1.1.192.in-addr.arpa    192.1.1.1       named.rev
--end /etc/named.boot--

The ip address noted for the secondary lines (192.1.1.1 in this
example) should be the IP address of the machine that is primary for
the domain.

The named.ca file should be retrieved as described in section 3.5.

The named.local file should be created as described in section 3.6.

The named.test and named.rev files will automatically be created when
in.named is started up, by downloading the information from the
primary server.

Note: although this example only shows secondary lines, machines can
actually combine primary and secondary lines in arbitrary ways. For
example, a machine could primary test.com, and secondary foo.org, as a
favor to a nearby domain.


 阿骁 回复于:2002-05-26 00:45:15
我顶。。。。:)

 byuq 回复于:2002-05-27 02:25:01
named.boot在solaris下用named-bootconf直接转换成named.conf多省事呀!!!

 aniu 回复于:2002-06-17 15:33:19
 楼上的MX记录没有写优先级

 boycw 回复于:2002-06-17 15:53:49
建议斑竹放到精华区!!!!!!!!!

 kellycdl 回复于:2002-10-18 17:37:48
请问阿骁,为什么我按你的配置文件做报错
***Can't find server name for address *。*。*。*(我dns server 的 ip地址): Server failed
*** Default servers are not available

在named.conf 文件中
allow-transfer { 202.x.x.x; };   ;只允许202.x.x.x进行域数据的传输
是必需的吗,是dns的真ip吗


 163 回复于:2002-10-19 07:27:22
很好,尽管有的是旧版的dns配置,但可以帮助理解dns系统。

1、bind4.x变到bind8.x的确有named-bootconf named.boot > named.conf 省事。想问问具体如何做,比如种个文件存放的路径?

2、IN MX记录没有写优先级,是不是有个默认值,是多少? 再问下里的这些记录应必须为大写吗?

3、还想知道allow-transfer{ ;}; 其中的分号在括号里,与括号外的是不是都不能少?(我记得在Turbo C,Turbo Pascal编程时,遇到结束的符号就自动为有结束此句的作用的)

另外allow-transfer语句的含义,它是允许本机文件信息向外传递,还是允许别的机子信息向本机传过来呀?也就是个方向问题

以上是我看到几个问题,希望各位朋友给以答复帮助,小弟先谢谢了!

 giant 回复于:2003-09-24 10:25:52
高手!!1

 yjj2597 回复于:2003-09-30 13:22:06
支持

原文转自:http://www.ltesting.net