人的头脑太复杂,时间过得久,有时候连自己也被自己骗了,记下来才是最真实的......开源技术博客,记录开源技术应用的点点滴滴。 注册 | 登陆

Linux下源代码编译bind9.6安装和配置DNS服务器

Linux下源代码编译bind9.6安装和配置DNS服务器

http://www.isc.org/products/BIND/ 下载bind最新 bind-9.6.1rc1.tar.gz
#./configure --prefix=/usr/local/named --enable-threads #--enable-threads开启多线程处理能力
#make
#make install
#cd /var/named
这是bsd的一个简单配置文件:

options {
directory       "/var/named";#我去哪找解析文件
pid-file        "/var/run/named/pid";进程文件放这吧
dump-file       "/var/dump/named_dump.db";
statistics-file "/var/stats/named.stats";

listen-on       { 192.168.0.83; };监听

notify yes;
logging {
channel query_log {
file "query.log";日志名
severity        info;级别 和syslog差不多的那种
print-time        yes;
print-category yes;
};
category queries {#分类Once a customized channel has been defined,          a category option is used to categorize the channel and begin logging when named is restarted
                      query_log;
};
};


forwarders {
221.228.255.1;159.226.5.65;
};#我解析不了就给他

};
include "acl.conf";

view "test" {
match-clients {xxx; }; #在acl.conf中定义
recursion no;

zone "." {
type hint;
file "named.root"; #dig >named.root 或者这下:ftp://ftp.rs.internic.net/domain/
};全球的根域名服务器

zone "0.0.127.IN-ADDR.ARPA" {
type master;
file "localhost.rev"; #sh make-localhost

或:

$TTL 86400 @ IN SOA @ root.localhost (
1 ; serial
28800 ; refresh 告诉某个区的辅域名服务器相隔多久检查该区的数据是否是最新的
7200 ; retry 如果辅域名服务器超过刷新时间后无法访问主域名服务器 那么就每隔一段重试时间就试着联系一次,重试时间通常比刷新时间要短
604800 ; expire 如果期满时间内辅助域名服务器还是无法与主域名服务器联系上 那么就宣布这个区失效,停止关于该区的任何查询应答
86400 ; ttl            否定缓存ttl值
)

官方推荐:刷新:24小时 重试 2小时 期满30天 默认ttl 4天
IN NS localhost.

@ IN A 127.0.0.1


};
zone "fashionfree.cn"{
type master;
file "fashionfree.fwd";
};
#zone "0.168.192.in-addr.arpa" {
# type master;
# file "master/test75.rev";
#};

使用rndc-confgen > rndc.conf生成key文件 然后通过tail -n10 rndc.conf | head -n9 | sed -e s/#\ //g >> named.conf将key文件写入name.conf

key "rndc-key" {
algorithm hmac-md5;
secret "YMVkQroow6D4rYGffjOkQw==";
};

controls {
inet 127.0.0.1/* port 953
allow { 127.0.0.1/any; } keys { "rndc-key"; };
};这决定rndc用户要用什么加密密钥来验证身份才能给域名服务器发送控制消息
 rndc 是 bind 软件引进的远程控制通道,代替 unix 信号来控制 named 进程,可以用来对配置进行重新载入

#named -c named.conf

 

 

notify — Controls whether named notifies the slave servers when a zone is updated. It accepts the following options:

  • yes — Notifies slave servers.

  • no — Does not notify slave servers.

  • explicit — Only notifies slave servers specified in an also-notify list within a zone statement.

    allow-update — Specifies the hosts that are allowed to dynamically update information in their zone. The default is to deny all dynamic update requests.

    acl.conf:

    acl "CNC" {
    58.16.0.0/16;

    xx.xx.xx.xx/xx;

    }

  • allow-recursion
    设定哪台主机可以进行递归查询。如果没有设定,缺省是允许所有主机进行递归查询。注意禁止一台主机的递归查询,并不能阻止这台主机查询已经存在于服务器缓存中的数据。
  • recursion
    如果是yes,并且一个DNS询问要求递归,那么服务器将会做所有能够回答查询请求的工作。如果recursion是off的,并且服务器不知道答案,它将会返回一个推荐(referral)响应。默认值是yes。注意把recursion设为no,不会阻止用户从服务器的缓存中得到数据,它仅仅阻止新数据作为查询的结果被缓存。服务器的内部操作还是可以影响本地的缓存内容,如NOTIFY地址查询。

    1.递归查询:
    一般客户机和服务器之间属递归查询,即当客户机向DNS服务器发出请求后,若DNS服务器本身不能解析,则会向另外的DNS服务器发出查询请求,得到结果后转交给客户机;
    2.迭代查询(反复查询):
    一般DNS服务器之间属迭代查询,如:若DNS2不能响应DNS1的请求,则它会将DNS3的IP给DNS2,以便其再向DNS3发出请求;

    举例:比如学生问老师一个问题,王老师告诉他答案这之间的叫递归查询。这期间也许王老师也不会,这时王老师问张老师,这之间的查询叫迭代查询!

    http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-bind-namedconf.html

    不能在父域里面设定子域主机的A记录,因为dns查询过程是先查询父域的,遇到子域的主机就自动通过NS记录 转到子域区文件里面去查询了。

    dns查询过程:以查询[url]www.chinaunix.net[/url]为例
    1 先到/etc/resolv.conf文件里面指定的域名服务器查询,没有相关记录,所以通过named.ca文件内设置的根服务器(.)列表,返回一个根服务器IP地址
    2 到根服务器(.)查询,同样没有。但是通过NS记录返回一个子域net的域名服务器IP地址
    3 到net子域服务器查询,发现二级子域chinaunix.net的NS记录(就是chinaunix通过域名注册机构注册的域名),返回一个chinaunix.net子域服务器IP (chinaunix内部架设的dns服务器)
    4   到chinaunix.net的dns服务器查询相应主机[url]www.chinaunix.net[/url]。终于找到,顺利返回相应IP地址。
    5 查询完毕.到[url]www.chinaunix.net[/url]相应主机的相应端口进行连接。^_^

     

    若你再見到你的老師,不妨請他告訴理論依據好讓你深入研究...
    然而,教育的要旨,不在於接受而在於懷疑。

    ns 授權很簡單...
    假設你註冊的 domain 叫 abc.com ,而你有 ns1   與 ns2 兩台 server 。
    那,你必需從 .com 的權威伺服器授權給你,其設定或類似如此:

    $ORIGIN com.
    abc IN NS ns1.abc.com.
    abc IN NS ns2.abc.com.
    ns1.abc IN A 1.2.3.4
    ns1.abc IN A 1.2.3.5

    然後,你的 ns1 或 ns2 都可是權威伺服器了(各自的 SOA 設為自己即可)。
    在 abc.com 的 db 中,最少還應類似如下的設定:

    $ORIGIN abc.com.
    @ IN NS ns1.abc.com.
    @ IN NS ns2.abc.com.
    ns1 IN A 1.2.3.4
    ns2 IN A 1.2.3.5

    不過,既然 SOA 是自己的話,那事實上,我可以改變 ns 或增加 ns 授權:

    $ORIGIN abc.com.
    @ IN NS ns1.abc.com.
    @ IN NS ns2.abc.com.
    @ IN NS ns3.abc.com.
    ns1 IN A 1.2.3.4
    ns2 IN A 1.2.3.5
    ns3 IN A 1.2.3.6

    假如你有 sub-zone 要授權,事實上也是利用 ns 啦:

    $ORIGIN abc.com.
    sub1 IN NS ns1.sub1.abc.com.
    sub1 IN NS ns2.sub1.abc.com.
    ns1.sub1 IN A 4.3.2.1
    ns2.sub1 IN A 4.3.2.2

    然而,不同版本的 resolver ,對最終的 ns 判定是不一樣的:
    bind9 是以 abc.com 的權威主機的 ns 為依據,若找不到,那就沒結果。
    而之前的版本,則可退而求次,以 com. 裡關於 abc.com 的 ns 為答案。
  • acl slave_servers { 192.168.0.2;192.168.0.3; };

    zone "mydomain.com" {
    type master;
    file "mydomain.com.zone";
    notify yes;
    allow-transfer { slave_servers; };
    also-notify { slave_servers; };
    };
  •  

    notify
    If yes (the default), DNS NOTIFY messages are sent when a zone the server is authoritative for
    changes, see Section 3.3. The messages are sent to the servers listed in the zone’s NS records
    (except the master server identified in the SOA MNAME field), and to any servers listed in the
    also-notify option.
    If explicit, notifies are sent only to servers explicitly listed using also-notify. If no, no notifies
    are sent.
    The notify option may also be specified in the zone statement, in which case it overrides the options
    notify statement. It would only be necessary to turn off this option if it caused slaves to crash.

    6.2.14.6
    also-notify
    Defines a global list of IP addresses of name servers that are also sent NOTIFY messages whenever
    a fresh copy of the zone is loaded, in addition to the servers listed in the zone’s NS records. This
    helps to ensure that copies of the zones will quickly converge on stealth servers. If an also-notify
    list is given in a zone statement, it will override the options also-notify statement. When a zone
    notify statement is set to no, the IP addresses in the global also-notify list will not be sent NOTIFY
    messages for that zone. The default is the empty list (no global notification list).

    使用notify指令会自动通知所有这个域的所有在ns记录上的机器,also-notify指令可以用来通知所有不在ns记录上的dns服务器。

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8

发表评论

评论内容 (必填):