Linux下源代码编译bind9.6安装和配置DNS服务器
Linux 下源代码编译bind9.6安装和配置DNS 服务器Linux 下源代码编译bind9.6安装和配置DNS 服务器#./configure --prefix=/usr/local/named
Linux 下源代码编译bind9.6安装和配置DNS 服务器
Linux 下源代码编译bind9.6安装和配置DNS 服务器
#./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 {
channelquery_log {
file "query.log";日志名
severity info; 级别和syslog 差不多的那种
print-time yes;
print-category yes;
};
category queries {#分类Once a customized channel has been defined,
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; a category
,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发出请求;
举例:比如学生问老师一个问题,王老师告诉他答案这之间的叫递归查询。这期间也许王老师也不会,这时王老师问张老师,这之间的查询叫迭代查询!
不能在父域里面设定子域主机的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 的權威伺服器授權給你,其設定或類似如此:
[Copy to clipboard] [ - ]CODE:
$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 中,最少還應類似如下的設定:
,[Copy to clipboard] [ - ]CODE:
$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 授權:
[Copy to clipboard] [ - ]CODE:
$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 啦:
[Copy to clipboard] [ - ]CODE:
$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 為答案。
aclslave_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 服务器。