Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7593676 建立时间:2006年5月29日 |

| |
[网站架构]DNS配置过程 软件技术
lhwork 发表于 2007/1/21 15:24:12 |
DNS配置过程
安装过程如下:# apt-get install bind9安装完毕后,用命令whereis bind可以发现bind安装在/etc/bind目录下,进入/etc/bind目录,看到目录下有这些文件:db.0db.127db.255db.emptydb.localdb.revdb.rootnamed.confnamed.conf.localnamed.conf.optionsrndc.key其中的关键文件是named.conf,我们可以查看它的内容:// This is the primary configuration file for the BIND DNS server named.//// Please read /usr/share/doc/bind9/README.Debian.gz for information on the // structure of BIND configuration files in Debian, *BEFORE* you customize // this configuration file.//// If you are just adding zones, please do that in /etc/bind/named.conf.localinclude "/etc/bind/named.conf.options";// prime the server with knowledge of the root serverszone "." {type hint;file "/etc/bind/db.root";};// be authoritative for the localhost forward and reverse zones, and for// broadcast zones as per RFC 1912zone "localhost" {type master;file "/etc/bind/db.local";};zone "127.in-addr.arpa" {type master;file "/etc/bind/db.127";};zone "0.in-addr.arpa" {type master;file "/etc/bind/db.0";};zone "255.in-addr.arpa" {type master;file "/etc/bind/db.255";};include "/etc/bind/named.conf.local";我
们注意到此文件include 两个文件"/etc/bind/named.conf.options"和
"/etc/bind/named.conf.local",此外是一些DNS解析区域及其记录文件。在此文件的注释里提示,如果要增加区域的话,可以编
辑/etc/bind/named.conf.local。文件/etc/bind/named.conf.options的内容如下:options {directory "/var/cache/bind";// If there is a firewall between you and nameservers you want// to talk to, you might need to uncomment the query-source// directive below. Previous versions of BIND always asked// questions using port 53, but BIND 8.1 and later use an unprivileged// port by default.// query-source address * port 53;// If your ISP provided one or more IP addresses for stable // nameservers, you probably want to use them as forwarders. // Uncomment the following block, and insert the addresses replacing // the all-0's placeholder.// forwarders {// 0.0.0.0;// };auth-nxdomain no; # conform to RFC1035};文件/etc/bind/named.conf.local的内容如下,基本没有内容://// Do any local configuration here//// Consider adding the 1918 zones here, if they are not used in your// organization//include "/etc/bind/zones.rfc1918";从以上内容可以看出,除DNS的本地域名外,其它部分已经正常。要增加本地域名解析只要编辑/etc/bind/named.conf.local,并增加相应记录文件即可。本目录下的其它文件不必更改。这时可以作一些测试。笔者的测试环境如下:三台电脑,一台装debian,一台装redhat8,一台装win98,准备设置根域名为home,相应的域名与IP对应关系如下:debian.home 192.168.10.103win98.home 192.168.10.102rh8.home 192.168.10.101在安装DNS前,各台机子的DNS设置为202.101.98.54,这是福建省的域名服务器,各台电脑间的互访通过hosts文件解析。在debian机子上,/etc/resolve.conf的内容如下:domain home.nameserver 202.101.98.54/etc/hosts的内容如下:### etherconf DEBCONF AREA. DO NOT EDIT THIS AREA OR INSERT TEXT BEFORE IT.127.0.0.1 localhost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allroutersff02::3 ip6-allhosts192.168.10.103 debian.home debian### END OF DEBCONF AREA. PLACE YOUR EDITS BELOW; THEY WILL BE PRESERVED.192.168.10.102 win98.home win98192.168.10.101 winme.home winme在redhat8电脑上的配置与此类似。在win98电脑上建立的/windows/hosts文件内容如下:192.168.10.103 debian.home debian192.168.10.102 win98.home win98192.168.10.101 winme.home winme也就是说在使用DNS前,它们用域名访问internet或互访都是正常。但现在我们要安装DNS,所以必须先它们去掉,才能知道所安装的DNS是否正常。步骤如下:在debian机子上,修改/etc/resolve.conf的内容如下:domain home.nameserver 192.168.10.103/etc/hosts的内容如下:### etherconf DEBCONF AREA. DO NOT EDIT THIS AREA OR INSERT TEXT BEFORE IT.127.0.0.1 localhost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allroutersff02::3 ip6-allhosts192.168.10.103 debian.home debian### END OF DEBCONF AREA. PLACE YOUR EDITS BELOW; THEY WILL BE PRESERVED.在redhat8电脑上的配置与此类似。在win98电脑上删除/windows/hosts文件。并打开控制面板,选网络,再选TCP/IP,在“首选DNS”里面,输入DNS为192.168.10.103,点击确定,重启电脑。此时你会发现,三台电脑用域名互访不行了,但访问internet上的域名,比如www.linuxsir.com都
可以。因此接下来的步骤是增加本地域名解析,即编辑/etc/bind/named.conf.local,并增加相应记录文件。方法我推荐使用
webmin-bind。当然如果你对记录文件格式很熟悉的话,可以手工编辑。我开始是采用手工编辑,浪费很多时间,直到我发现了webmin-
bind。#apt-get install webmin webmin-bind安装完成后,在游览器的URL里输入https://localhost:10000/,
输入用户名及密码进入webmin,即可看到BIND
DNS服务器,点击进入,点击创建主区域,在出现的新建主区域选项中的区域类型单选框选正向(名称至地址),在域名 /
网络编辑框中输入home,在主服务器编辑框中输入debian.home,在Email
地址编辑框中输入root.debian.home,其它按默认。点击保存。再点击home主区域,点击地址,增加三条地址记录。再次点击创建主
区域,在出现的新建主区域选项中的区域类型单选框选反向(地址至名称),在域名 /
网络编辑框中输入192.168.10,在主服务器编辑框中输入debian.home,在Email
地址编辑框中输入root.debian.home,其它按默认。点击保存。再点击192.168.10主区域,点击反向地址,增加三条地址记录。单击启动名字服务器按钮运行 BIND 服务器, 并装载当前配置。这样就完成了增加本地域名解析的工作,DNS也大功告成了。可以在各台电脑上测试一下,用域名访问internet或互访都不成问题。但我们需要进一步知道webmin-bind作了哪些修改。这时的/etc/bind/named.conf的内容如下:// This is the primary configuration file for the BIND DNS server named.//// Please read /usr/share/doc/bind9/README.Debian.gz for information on the // structure of BIND configuration files in Debian, *BEFORE* you customize // this configuration file.//// If you are just adding zones, please do that in /etc/bind/named.conf.localinclude "/etc/bind/named.conf.options";// prime the server with knowledge of the root serverszone "." {type hint;file "/etc/bind/db.root";};// be authoritative for the localhost forward and reverse zones, and for// broadcast zones as per RFC 1912zone "localhost" {type master;file "/etc/bind/db.local";};zone "127.in-addr.arpa" {type master;file "/etc/bind/db.127";};zone "0.in-addr.arpa" {type master;file "/etc/bind/db.0";};zone "255.in-addr.arpa" {type master;file "/etc/bind/db.255";};include "/etc/bind/named.conf.local";zone "home" {type master;file "/var/cache/bind/home.hosts";};zone "10.168.192.in-addr.arpa" {type master;file "/var/cache/bind/192.168.10.rev";};我
们可以发现只是末尾增加了两个zone。而且在/etc/bind/目录下的其它文件都没有改动,我们可以从文件的修改时间看出。增加的两个记录文件是
/var/cache/bind/home.hosts,/var/cache/bind/192.168.10.rev。它们的内容如下:/var/cache/bind/home.hosts的内容如下:$ttl 38400home. IN SOA debian.home. root.debian.home. (103910209010800360060480038400 )home. IN NS debian.home.debian.home. IN A 192.168.10.103rh8.home. IN A 192.168.10.101win98.home. IN A 192.168.10.102/var/cache/bind/192.168.10.rev的内容如下:$ttl 3840010.168.192.in-addr.arpa. IN SOA debian.home. root.debian.home. (103910245310800360060480038400 )10.168.192.in-addr.arpa. IN NS debian.home.101.10.168.192.in-addr.arpa. IN PTR rh8.home.102.10.168.192.in-addr.arpa. IN PTR win98.home.103.10.168.192.in-addr.arpa. IN PTR debian.home.这些格式与网上很多文章介绍的有些不同,所以我才想写出来,希望其它初学者不要象我一样,一头雾水好几天。DNS设置完了后,如果不能保证DNS机子一直开着,可以在其它机子上加上其它DNS,比如202.101.98.54。以免 本地DNS机子关机的时候,不能通过域名访问internet。 |
|
|