BIND域名服务器配置
在 “动态域名更新(DDNS+DHCPD)”的这个http://www.linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=13288
帖子里,我大概地写了 bind 的配置,这里详细地写一个。
本 人 申 明 :
我这里的例子均是本人在实际环境里面使用过的,只是改变了yourdomaon.com、1.2.3 等。
所以您可以完全拷贝我的。
然后将 “yourdomaon.com” 改成你的“域名”;
将“1.2.3”、“3.2.1” 改成您的(比如)“192.168.0”、“0.168.192”(私网和公网均可) 即可!
所用到的文件 :
3.2.1 29-Jan-2002 17:04745
127.0.0 29-Jan-2002 17:00278
localdomain 29-Jan-2002 17:00296
named.ca 04-Jul-2001 04:562.7K
named.conf 20-Dec-2002 13:213.2K
named.root 04-Jul-2001 04:562.7K
yourdomain.com 29-Jan-2002 17:04953
named.cond 文件内容:
#
# file: /etc/named.conf
#
# It's ONLY for reference. ------------- gugong
#
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
include "/etc/rndc.key";
logging {
channel gugong_update_debug {
file "/var/named/update-debug.log"; #您须手工 touch 此文件,然后改为 named 用户所有,下同。
severitydebug 3 ;
print-category yes;
print-severity yes;
print-time yes;
};
channel gugong_security_info {
file "/var/named/named-auth.log";
severityinfo;
print-category yes;
print-severity yes;
print-time yes;
};
channel gugong_queries_info {
file "/var/named/queries.log";
severityinfo;
print-category yes;
print-severity yes;
print-time yes;
};
channel gugong_default_info {
file "/var/named/named-default.log";
severityinfo;
print-category yes;
print-severity yes;
print-time yes;
};
category update {
gugong_default_info;
gugong_update_debug;
default_syslog;
default_stderr;
};
category security {
gugong_security_info;
default_debug;
default_syslog;
};
category queries {
gugong_queries_info;
# default_syslog;
default_debug;
};
category lame-servers {
gugong_queries_info;
default_syslog;
};
category default {
gugong_default_info;
default_syslog;
default_debug;
default_stderr;
};
# 不同的 bind 版本,可能上面的有些不能用,注释掉不能用的即可。
};
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
options {
directory "/etc/named";
# 指定域名解析文件的存放目录为 "/etc/named"。
/*
* 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 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
auth-nxdomain yes;
# check-names master fail;
# check-names slave warn;
# check-names response ignore;
#
# 可以指定在哪个地址监听。
# listen-on port 53 { 127.0.0.1; 192.168.0.251; };
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ========================================================================
# 提供 “域名解析转发”。
# 这在若你没有直接连接到互联网时会特别管用。
# 当然您也可以指定这里,来减少您服务器的 DNS 解析的网络流量。
#
# forward first;
# forwarders { 192.168.0.1; 192.168.0.2; };
#
#
# rfc2308-type1 yes; #no
};
#
acl local_host_name {
192.168.0.0/24;
# !192.168.1.239;
};
#
zone "yourdomain.com" in {
type master;
file "master/yourdomain";
# allow-update { local_host_name; };
# check-names warn;
# ( warn | fail | ignore );
};
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
zone "3.2.1.in-addr.arpa" {
type master;
notify no;
file "master/3.2.1";
# allow-update { local_host_name; };
# check-names warn;
# ( warn | fail | ignore );
};
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#
# hint file (formerly known as cache file)
zone "." {
type hint;
file "named.ca";
# check-names warn;
# ( warn | fail | ignore );
};
#
/* localhost */
zone "0.0.127.in-addr.arpa" {
type master;
notify no;
file "master/127.0.0";
};
#
/* localhost.localdomain */
zone "localdomain" {
type master;
notify no;
file "master/localdomain";
};
# ------------------------ END ------------------------
yourdomain.com 文件(正向)内容:
;
; file: yourdomain.com
;
; It's ONLY for reference. ------------- gugong
;
;
;$INCLUDE <FileName> <opt_domain>
$ORIGIN yourdomaon.com.
$TTL 144000
@ IN SOA yourdomaon.com. hostmaster.yourdomaon.com. (
2002010828 ; Serial
3H ; Refresh
2H ; Retry
4W ; Expire
3D ) ; Minimum
IN NS ns1.yourdomaon.com.
IN NS ns2.yourdomaon.com.
IN MX 10 mail.yourdomaon.com.
TXT "Your Corporation"
yourdomaon.com. IN A 1.2.3.4
IN MX 10 mail.yourdomaon.com.
www.yourdomaon.com. IN A 1.2.3.5
IN MX 10 mail.yourdomaon.com.
ns1.yourdomaon.com. IN A 1.2.3.6
IN MX 10 mail.yourdomain.com.
ns2.fruitron.com.cn. IN A 1.2.3.7
IN MX 10 mail.yourdomaon.com.
mail.yourdomaon.com. IN A 1.2.3.4
IN MX 10 mail.yourdomaon.com.
;
;
;pop IN CNAME mail.yourdomaon.com.
;pop3 IN CNAME mail.yourdomaon.com.
;imap IN CNAME mail.yourdomaon.com.
;
; ================ END ================
3.2.1 文件(反向)内容:
;
; file: 3.2.1
;
; It's ONLY for reference.--------- gugong
;
;
;$INCLUDE <FileName> <opt_domain>
$ORIGIN 3.2.1.in-addr.arpa.
$TTL 144000
@ IN SOA yourdomain.com. hostmaster.yourdomain.com. (
2002010838 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS ns1.yourdomain.com.
IN NS ns2.yourdomain.com.
IN MX 10 mail.yourdomain.com.
4 IN PTR yourdomain.com.
IN MX 10 mail.yourdomain.com.
5 IN PTR www.yourdomain.com.
IN MX 10 mail.yourdomain.com.
6 IN PTR ns1.yourdomain.com.
IN MX 10 mail.yourdomain.com.
7 IN PTR ns2.yourdomaon.com.
IN MX 10 mail.yourdomain.com.
4 IN PTR mail.10 mail.yourdomain.com.
IN MX 10 mail.yourdomain.com.
;
;
localdomain 文件内容:
;
; file: localdomain
;
; It's ONLY for reference. ------------- gugong
;
$TTL 86400
$ORIGIN localdomain.
@ IN SOA localhost. root.localhost. (
2002010748 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS localhost.
localhost IN A 127.0.0.1
127.0.0文件内容:
;
; file: 127.0.0
;
; It's ONLY for reference. ------------- gugong
;
$TTL 86400
@ IN SOA localhost. root.localhost.(
2002010698 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
1 IN PTR localhost.
named.ca(或者named.root)的内容,我就不帖了。 新 BIND 版本支持 view 项。
可以让某个 zone 只为某些指定的用户服务。意味着:
您可以在自己公司的服务器上建一个你私人的虚拟主机,而局域网不可以访问,公网的用户却可以访问(在 dns 、网关为您控制的情况下,我原来就是这么做的哟)。
named.conf 文件内容:
// generated by named-bootconf.pl
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
include "/etc/rndc.key";
logging {
channel gugong_update_debug {
file "/var/named/update-debug.log"; #您须手工 touch 此文件,然后改为 named 用户所有,下同。
severitydebug 3 ;
print-category yes;
print-severity yes;
print-time yes;
};
channel gugong_security_info {
file "/var/named/named-auth.log";
severityinfo;
print-category yes;
print-severity yes;
print-time yes;
};
channel gugong_queries_info {
file "/var/named/queries.log";
severityinfo;
print-category yes;
print-severity yes;
print-time yes;
};
channel gugong_default_info {
file "/var/named/named-default.log";
severityinfo;
print-category yes;
print-severity yes;
print-time yes;
};
category update {
gugong_default_info;
gugong_update_debug;
default_syslog;
default_stderr;
};
category security {
gugong_security_info;
default_debug;
default_syslog;
};
category queries {
gugong_queries_info;
# default_syslog;
default_debug;
};
category lame-servers {
gugong_queries_info;
default_syslog;
};
category default {
gugong_default_info;
default_syslog;
default_debug;
default_stderr;
};
# 不同的 bind 版本,可能上面的有些不能用,注释掉不能用的即可。
};
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
options {
directory "/etc/named/named.fruitron";
# 指定域名解析文件的存放目录为 "/etc/named"。
/*
* 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 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
auth-nxdomain yes;
# check-names master fail;
# check-names slave warn;
# check-names response ignore;
# listen-on port 53 { 127.0.0.1; 192.168.10.8; 192.168.20.8; 211.148.130.133; };
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ========================================================================
# forward first; # 缺省值
# forwarders { 202.96.128.143; 202.96.134.133; 202.96.128.68; 202.66.145.179; };
# rfc2308-type1 yes; # 缺省值 no
};
#
acl local_host_name {
192.168.20.0/24;
# !192.168.1.239;
};
# when using 'view' statements, all zones must be in views.
#
view "internal" {
// This should match our internal networks.
match-clients { 192.168.10/24; 192.168.20/24; 192.168.30/24; };
// Provide recursive service to internal clients only.
recursion yes;
# hint file (formerly known as cache file)
zone "." {
type hint;
file "named.ca";
# check-names warn;
# ( warn | fail | ignore );
};
#
/* localhost */
zone "0.0.127.in-addr.arpa" {
type master;
notify yes;
file "master/127.0.0";
};
#
/* localhost.localdomain */
zone "localdomain" {
type master;
notify yes;
file "master/localdomain";
};
zone "fruitron.com.cn" in {
type master;
notify yes;
file "master/fruitron.com.cn.internal";
allow-update { local_host_name; };
# check-names warn;
# ( warn | fail | ignore );
};
zone "20.168.192.in-addr.arpa" {
type master;
notify yes;
file "master/192.168.20";
allow-update { local_host_name; };
# check-names warn;
# ( warn | fail | ignore );
};
};
#
view "external" {
match-clients { any; };
// Refuse recursive service to external clients.
recursion no;
zone "fruitron.com.cn" in {
type master;
notify yes;
file "master/fruitron.com.cn.external";
# allow-update { local_host_name; };
# check-names warn;
# ( warn | fail | ignore );
};
#zone "511888.com" in {
# type master;
# file "master/511888.com";
# notify yes;
# allow-update { local_host_name;
# check-names warn;
#};
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
zone "130.148.211.in-addr.arpa" {
type master;
notify yes;
file "master/211.148.130";
# allow-update { local_host_name; };
# check-names warn;
# ( warn | fail | ignore );
};
};
别的文件我就不帖了,可以参考:
http://shcore.com.cn/gugong/gugong/linux/config/named.NEW/named.fruitron/
或者:
http://www.ehuilong.com/gugong/gugong/linux/config/named.NEW/named.fruitron/ ;
; file: 3.2.1
;
; It's ONLY for reference.--------- gugong
;
;
;$INCLUDE <FileName> <opt_domain>
$ORIGIN 3.2.1.in-addr.arpa.
$TTL 144000
@ IN SOA [b]yourdomain.com. [/b]hostmaster.yourdomain.com. (
2002010838 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
SOA 后面不是应该是主机吗? 看了很久没有看懂1!!
我会仔细看得! 不太明白这些是什么意思?
logging {
channel gugong_update_debug {
file "/var/named/update-debug.log"; #您须手工 touch 此文件,然后改为 named 用户所有,下同。
severitydebug 3 ;
print-category yes;
print-severity yes;
print-time yes;
};
channel gugong_security_info {
file "/var/named/named-auth.log";
severityinfo;
print-category yes;
print-severity yes;
print-time yes; 版主给讲解一下脚本吧。 man named.conf 帮主麻烦给解决一个问题:
我用linux做网关,内部网的电脑透明出去。
我在网关上启用了dns服务,
内部网电脑的dns查询也是通过这个网关的,这个一起都很正常。
现在有个问题:我想把一个域名比如www.mydomain.com指向内部网的一个地址(比如192.168.0.123).就是内部网的电脑如果访问www.mydomain.com,向网关的dns查询的结果是192。168。0。123。
我在named.conf总也设置了mydomain.com的zone,同样在/var/named/下面也配置了文件。但是查询的时候就是不能用的(或者得到的是公网的地址,我其实想要的是内部的地址)。如果解决,请指点。 帮主麻烦给解决一个问题:
我用linux做网关,内部网的电脑透明出去。
我在网关上启用了dns服务,
内部网电脑的dns查询也是通过这个网关的,这个一起都很正常。
现在有个问题:我想把一个域名比如www.mydomain.com指向内部网的一个地址(比如192.168.0.123).就是内部网的电脑如果访问www.mydomain.com,向网关的dns查询的结果是192。168。0。123。
我在named.conf总也设置了mydomain.com的zone,同样在/var/named/下面也配置了文件。但是查询的时候就是不能用的(或者得到的是公网的地址,我其实想要的是内部的地址)。如果解决,请指点。
加上参数
auth-nxdomain yes;
试一试,若不行,加上 view 项,肯定可以的。
折腾了一下,终于找出毛病来了
用了斑竹的方法试了一下,还是不行.只好自己折腾,我用的fedora core 1 最近的update.
后来用ps -A -f 查看的时候
发现named 的命令行是/usr/sbin/named -u named -t /var/named/chroot
问题就在-t /var/named/chroot 这个参数
到这个目录一看,原来这里也有配置文件,修改这里的配置文件,
restart service,一切ok!