您的位置:首页 > 其它

FreeBSD学习笔记24-安装DNS服务

2008-11-12 20:47 716 查看

一、准备

1、成为超级用户。2、BIND 9.4.2 是 FreeBSD 7.0 标准分发中的一部分。用下列命令可以查核 ports 中的 BIND 是否有效。# cat /usr/ports/dns/bind94/Makefile | grep PORTVERSION如果版本显示为“9.4.2”,跳到“配置”章节。否则,进入“安装”章节。

二、安装

用下列命令开始 BIND 的安装。# cd /usr/ports/dns/bind94# make config ; make install clean注意勾选 REPLACE_BASE项。

三、配置

1、添加下列命令到 /etc/make.conf 文件。# cp /etc/make.conf /etc/make.conf.old# echo "NO_BIND = YES" >> /etc/make.conf这告诉 make 命令当从源码重构 FreeBSD 时不要创建基本的 BIND ,以防止系统下载了旧版的 BIND 。2、编辑 /var/named/etc/namedb/named.conf 文件。# ee /var/named/etc/namedb/named.conf3、用两个斜线(//)注释掉 listen-on 语句(大约在~21行)。这允许 BIND 的名称守护进程既可以接收外部的 DNS 查询,也可以接收本地的 DNS 查询。默认的仅接收本地查询。// listen-on { 127.0.0.1; };4、下滚到大约(~43-47)行。去掉 forwarders 语句前面的斜线和星号(/*)注释语句。替换 127.0.0.1 为你的 ISP 的名称服务器。 用英文分号(;)分割多个名称服务器。去掉末尾的斜线和星号(/*)注释语句。forwarders {202.13.68.62;68.103.31.52;};5、下滚到 named.conf 文件底部,添加下面的语句创建你的正向查找域。注意替换 example.com 为你的域名。注意:BIND 有个称为动态DNS更新的功能允许 BIND 和 ISC DHCP 服务器一起工作。并且当客户端加入和脱离你的本地网时,自动添加/删除你的域文件中的条目。如果你想启用动态更新功能,将上面代码 file 行的 master 更改为 dynamic 。6、如果你是直接连接到 Internet (非 NAT 路由)并且有一个动态的公网 IP 地址,跳到第8步。如果你是直接连接到 Internet 并且有个静态的公网 IP 地址,或者有个处于 NAT 路由后面的本地静态 IP 地址,添加下面的行到正向查找域(第5步中创建)后面。这将定义你的反向查找域。替换前3个8位字节 1.168.192 为你的服务器的静态 IP 地址,注意用倒序。如果你的本地网的子网是 192.168.1.XXX ,那么 1.168.192 就是正确的写法。替换 example.com 为你的域名。注意:如果你想启用动态更新功能,将上面代码 file 行的 master 更改为 dynamic 。7、记下反向查找域的名称(在这个例子中是 1.168.192.in-addr.arpa )。后面创建反向查找域文件时要用到它。保存并退出。8、创建 rndc.key 文件并添加它的内容到 named.conf 文件的末尾。rndc.key 文件是rndc程序加密的密钥,它通常用于当动态 DNS 更新时,鉴别 BIND 中合法的 DHCP 服务器。下面的命令创建密钥并且添加它到 named.conf 文件末尾。# rndc-confgen -a# cd /var/named/etc/namedb# cp named.conf named.conf.old# cat rndc.key >> named.conf9、创建主正向查找域文件。替换 example.com 为你的域名,此域名必须是你在上面第5步中指定的域名。# cd /var/named/etc/namedb/master# ee example.comexample.com 正向查找域文件:
注意:行前面有分号(;)的将被 BIND 忽略。
$TTL    3600
example.com. is the forward zone name.IN is a data type that means Internet data.SOA stands for start of authority.host.example.com. is the hostname of computer that holds this zone file.root.example.com symbol is used to represent the zone name, so the period is used to separate the username from the domain name in the email address).( The left parenthesis indicates the start of the SOA record.
1       ;       Serial
The serial number is a number you can choose; it is usually increased by one every time you make a change to the zone file. You may use a date (in the format YYYYMMDD) instead.
10800   ;       Refresh
If there is a slave server configured, this is the number of seconds it waits before contacting this master server for an update.
3600    ;       Retry
This is the number of seconds a slave server would wait before retrying a connection to the master server if it ever loses contact.
604800  ;       Expire
If the slave server cannot contact the master server within this time, in seconds, it will stop answering DNS queries.
86400 ) ;       Minimum TTL
This is the amount of time in seconds that a negative answer is cached. If a client tries to resolve a host that does not exist, the server will answer negatively until this time runs out before actually trying to resolve the address again.
;DNS Servers  example.com.    IN      NS              host.example.com.
example.com. is the forward zone's name or domain name.NS is a record type meaning nameserver.host.example.com. is the fully qualified domain name of the nameserver. (The period at the end means the FQDN is absolute; without it, named would automatically append example.com to it—so don't forget the period.)
;Machine Names  host.example.com.    IN      A               192.168.1.11
host.example.com. is the FQDN of a host on the domain.A is a record type meaning a host address.192.168.1.11 is the IP address of the host (IP addresses don't need terminating periods; they are considered absolute).
;Aliases  www                  IN      CNAME           host.example.com.
www is the FQDN of the aliased host on the domain. (Notice that there is no period after www; named will automatically append the domain example.com. If this is confusing, you may simply type www.example.com. here instead.)CNAME is a record type meaning canonical name for an alias.host.example.com. is the actual hostname of the alias.
;MX Record  example.com.         IN      MX      10      host.example.com.
example.com. is the MX's domain name.MX is a record type meaning mail exchanger.10 is the priority of the specified mail server. (Email destined for your domain will be directed to the highest priority mail server, then lower priority mail servers; the lower number is the higher priority.)host.example.com. is the FQDN of mail server (no IP addresses).10、创建完了正向查找域文件,保存并退出。11、创建反向查找域文件,名称为 example.com.rev 。如果你在上面的第6步中没有指定一个反向查找域,跳到“测试”章节。这个文件包含正向查找域文件中同样的内容,所有的 A 记录类型和 CNAME 记录类型变成了 PTR 记录类型。替换 example.com 为你的域名,此域名必须匹配你在第5步中指定的域名。# ee example.com.revexample.com 反向查找域文件,位于 /var/named/etc/namedb/master :下面是这个文件的详细解说。
1.168.192.in-addr.arpa. IN  SOA host.example.com.  root.example.com.
1.168.192.in-addr.arpa. is the reverse zone's name. It should match what you entered in the named.conf file (refer to step 7 on page 76).
;DNS Servers  1.168.192.in-addr.arpa.   IN      NS              host.example.com.
The DNS server NS record should point to the reverse zone's name. An @ symbol here would work too. In the context of DNS zone files, the @ symbol represents the zone's name.
;Machine IPs  11              IN      PTR             host.example.com.
11 is the last octet of host.example.com's IP address.PTR is a record type meaning pointer.Notice the 11 above does not end with a period. It will be automatically prefixed to this file's zone name (1.168.192.in-addr.arpa.). The result will point host.example.com to a reverse IP of 11.1.168.192.in-addr.arpa.. When your reverse zone file is complete, save and exit.12、如果你不启用动态 DNS 更新,跳到“测试”章节。BIND 默认是期望正向查找和反向查找域文件存储在 /var/named/etc/namedb/dynamic 目录。如果启动动态 DNS 更新,复制这两个域文件到 /var/named/etc/namedb/dynamic 目录。# cd /var/named/etc/namedb/master# cp example.com ../dynamic# cp example.com.rev ../dynamic# chown -R bind /var/named/etc/namedb/dynamic记得替换 example.com 为你的域名。

四、测试

1、编辑 resolv.conf 文件中的名称服务器条目,让它指向回环或者本机地址(127.0.0.1)。这将强迫系统在企图查询其它 DNS 服务器前查询本地 DNS 服务器。# ee /etc/resolv.confdomain example.comnameserver 127.0.0.1nameserver 61.32.24.84nameserver 206.13.22.96--------------------------------------------------------------------------------Note: 你最多可以指定3个名称服务器。--------------------------------------------------------------------------------保存退出。2、配置名称服务守护进程随系统启动。# ee /etc/rc.conf添加下面的行:named_enable="YES"保存退出。3、开始名称服务守护进程。# /etc/rc.d/named start保存退出。4、执行一个基本的到 google.com 的 DNS 查询。# dig baidu.com; <<>> DiG 9.4.2 <<>> baidu.com;; global options: printcmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34769;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 4, ADDITIONAL: 4;; QUESTION SECTION:;baidu.com. IN A;; ANSWER SECTION:baidu.com. 4344 IN A 220.181.38.84baidu.com. 4344 IN A 202.108.22.46;; AUTHORITY SECTION:baidu.com. 67802 IN NS ns2.baidu.com.baidu.com. 67802 IN NS ns3.baidu.com.baidu.com. 67802 IN NS dns.baidu.com.baidu.com. 67802 IN NS ns4.baidu.com.;; ADDITIONAL SECTION:ns3.baidu.com. 57113 IN A 220.181.37.10ns4.baidu.com. 74767 IN A 220.181.38.10dns.baidu.com. 165094 IN A 202.108.22.220ns2.baidu.com. 165094 IN A 61.135.165.235;; Query time: 30 msec;; SERVER: 192.168.0.80#53(192.168.0.80);; WHEN: Wed Nov 12 19:17:33 2008;; MSG SIZE rcvd: 195上面输出结果中粗斜体部分表明了这个 DNS 查询是由本地 DNS 服务器响应的。5、下面的命令发起一个众所周知的域传输 DNS 查询。这将测试正向查找域文件。注意替换 example.com 为你的域名。# dig example.com axfr; <<>> DiG 9.4.1 <<>> example.com axfr;; global options: printcmdexample.com. 3600 IN SOA host.example.com.example.com. 3600 IN MX 10 host.example.com.example.com. 3600 IN NS host.example.com.host.example.com. 3600 IN A 192.168.1.11www.example.com. 3600 IN CNAME host.example.com.example.com. 3600 IN SOA host.example.com.;; Query time: 1 msec;; SERVER: 127.0.0.1#53(127.0.0.1);; WHEN: Sat Jun 7 09:58:01 2008;; XFR size: 6 records (messages 1, bytes 189)这将检验你的 DNS 服务器是否返回正确的信息。如果你遇到问题,用文本编辑器查核 /var/log/messages 文件。很多问题是因为域文件中的语法错误。

五、实用程序

rndc 程序。1、命令:rndc语法:rndc option2、optins:flush  刷新 DNS 服务器的缓存。reload  重载配置文件和域。stop  保存更新到域文件并且停止服务。status  显示服务器状态。3、举例。刷新 DNS 服务器缓存。# rndc flush

六、文件位置

1、配置文件:/var/named/etc/namedb/named.conf名称服务的主配置文件。/var/named/etc/namedb/rndc.key包含加密的密钥文件,通常利用 rndc 命令控制名称服务守护进程。也用于当动态 DNS 更新时,验证 ISC 的 DHCP 服务器。2、日志文件:/var/log/messages错误和状态信息。

七、注意

如果你打算运行你自己的公众授权的 Internet DNS 服务器,你需要从你的 Internet 服务商哪里获取一个公网静态IP,这需要费用。你的域名注册注册商需要这个静态IP地址发送你的域的DNS查询到你的DNS服务器。如果你没有公网静态IP地址,你需要域名注册商或者第三方的服务驻留你的域名。你仍然可以在没有公网静态IP的情况下,运行本地授权的DNS服务器(在你的私有网络中)。如果你运行一个本地授权的DNS服务器,并且你利用DHCP配置你的网络客户端,确保修改你的DHCP服务器的配置指向客户端为你的DNS服务器IP。这将确保你的本地域客户端从你的DNS服务器缓存和域信息中受益。如果你位于NAT路由后面并且没有打算用你的Internet上权威的DNS服务器,在你的路由器的配置中关闭53端口(默认这应该是关闭的)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: