2014-12-23 16:11:09
来 源
中存储网
sendmail
如何在Linux系统中的dns服务器配置设置方法:1. 首先应确认你的上级域名服务器已正确指向你的DNS Server, 如我设置的 子域为net.dlut.edu.cn,则应在dlut.edu.cn的域名服务器上有到作 net.dlut.edu.cn子域名服务器的LINUX机器的的NS记录。

如何在Linux系统中的dns服务器配置设置方法

1. 首先应确认你的上级域名服务器已正确指向你的DNS Server, 如我设置的
   子域为net.dlut.chinastor.com,则应在dlut.chinastor.com的域名服务器上有到作
   net.dlut.chinastor.com子域名服务器的LINUX机器的的NS记录,以下是在
   dlut.chinastor.com域名服务器相应文件内容:
(1)BIND 4.9.x的配置文件
--------------------------/etc/named.boot----------------------
directory       /etc/namedb
;
primary         dlut.chinastor.com             db.dlut
primary         66.118.202.in-addr.arpa db.202.118.66
;
;
primary         0.0.127.in-addr.arpa    localhost.rev
secondary       net.dlut.chinastor.com     202.118.65.1 db.net.dlut
secondary       65.118.202.in-addr.arpa 202.118.65.1 db.202.118.65
;
; load the cache data last
cache           .                       named.root (2)Bind-8.x 配置文件 /etc/named.conf
// generated by named-bootconf.pl
options {
        directory "/etc/namedb";
        /*
         * 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;
};
// type    domain               source host/file                backup file
zone "." {
        type hint;
        file "named.root";
};
zone "0.0.127.IN-ADDR.ARPA" {
        type master;
        file "localhost.rev";
};
zone "66.118.202.IN-ADDR.ARPA" {
        type master;
        file "db.202.118.66";
};
zone "dlut.chinastor.com" {
        type master;
        file "db.dlut";
};
zone "net.dlut.chinastor.com" {
        type slave;
        file "db.net.dlut";
        masters {
202.118.65.1;
        }
};
zone "65.118.202.IN-ADDR.ARPA" {
        type slave;
        file "db.202.118.65";
        masters {
202.118.65.1;
        }
};
-------------------------/etc/namedb/db.dlut-------------------
@       IN      SOA     cedrus.dlut.chinastor.com. hbwork.dlut.chinastor.com.
99060205 10800 4800 604800 432000 )
IN      NS      cedrus.dlut.chinastor.com.
IN      NS      gingko.dlut.chinastor.com.
IN      NS      olive.dlut.chinastor.com.
IN      MX      1 gingko.dlut.chinastor.com.
localhost       IN      A       127.0.0.1
cedrus          IN      MX      1 gingko.dlut.chinastor.com.
IN      A       202.118.66.6
linden          IN      A       202.118.66.88
IN      MX      1 linden.dlut.chinastor.com.
ftp             IN      CNAME   linden.dlut.chinastor.com.
banyan          IN      CNAME   linden.dlut.chinastor.com.
gingko          IN      MX      10 gingko.dlut.chinastor.com.
IN      A       202.118.66.8
mail            IN      CNAME   gingko.dlut.chinastor.com.
rose            IN      MX      1 rose.dlut.chinastor.com.
IN      A       202.118.66.5
IN      A       202.118.69.6
bbs             IN      CNAME   rose.dlut.chinastor.com.
bbs1            IN      A       202.118.69.6
lib     604800  IN      NS      ns.lib.dlut.chinastor.com.
ns.lib  604800  IN      A       202.118.68.241
net     26000   IN      NS      dns.net.dlut.chinastor.com.
IN      NS      cedrus.dlut.chinastor.com.
dns.net         IN      A       202.118.65.1
IN      A       202.118.66.13
olive           IN      A       202.118.70.1
IN      A       202.118.71.1
IN      A       202.118.66.16
IN      A       202.118.68.1
IN      A       202.118.69.1
IN      MX      1 olive.dlut.chinastor.com.
peony           IN      A       202.118.66.18
www             IN      CNAME   peony.dlut.chinastor.com.
mirror          IN      CNAME   peony.dlut.chinastor.com.
       
可通过nslookup 确认是否已正确设定,如下:
> net.dlut.chinastor.com
Server:  cedrus.dlut.chinastor.com
Address:  202.118.66.6
Non-authoritative answer:
net.dlut.chinastor.com nameserver = dns.net.dlut.chinastor.com
net.dlut.chinastor.com nameserver = cedrus.dlut.chinastor.com
Authoritative answers can be found from:
dns.net.dlut.chinastor.com     internet address = 202.118.65.1
dns.net.dlut.chinastor.com     internet address = 202.118.66.13
cedrus.dlut.chinastor.com      internet address = 202.118.66.6
** 如果只想作本地的DNS Server或者你与Internet没有连接,可以忽略此步。

2。编辑net.dlut.chinastor.com DNS服务器的相应文件,
(1)Bind 4.9.x /etc/named.boot内容如下,其中以引号开始的内容为注释:
directory   /etc/namedb      ;指定named初始化文件目录,
;最好为一单独文件系统,如
;/var/namedb /usr/local/namedb
;cache 指向顶级域名服务器列表
cache      .                          root.cache
;primary 表明是子域net.dlut.chinastor.com和反向域65.118.202.IN-ADDR.ARPA
;的主域名服务器,其初始化文件分别为/etc/namedb/db.net.dlut和
;/etc/namedb/db.202.118.65
primary    net.dlut.chinastor.com            db.net.dlut
primary    65.118.202.IN-ADDR.ARPA    db.202.118.65
;本地回环域0.0.127.IN-ADDR.ARPA的主域名服务器
primary    0.0.127.IN-ADDR.ARPA       localhost.rev
;子域dlut.chinastor.com的备份域名服务器,从域名服务器202.118.66.6(primary
; server for domain dlut.chinastor.com)和202.118.66.8(secondary server for
; domain dlut.chinastor.com)申请相关数据,备份文件名为dlut.bak
; 如不做备份域名服务器则无须下列行
secondary  dlut.chinastor.com 202.118.66.6 202.118.66.8 dlut.bak
secondary  66.118.202.IN-ADDR.ARPA 202.118.66.6 202.118.66.8 dlut.rev.bak
(2) bind-8.x,可用其提供的namedboot-conf.pl将上面的文件内容
      转换为bind8所需的named.conf, 其中namedboot-conf.pl在redhat上可以在
/usr/doc/bind*/下找到,也可从bind8的代码包中拿到,其用法如下:
      $namedboot-conf.pl named.boot > named.conf
      将生成的named.conf文件复制到/etc目录下即可。

3.创建文件/etc/namedb/db.net.dlut,可从bind软件包携带的示例文件进行修改
  而成,文件内容如下:
-----------------------------------------------------------------------
;
; Data file of hostnames in this zone.
;
@       IN      SOA     dns.net.dlut.chinastor.com. hbwork.dlut.chinastor.com. (
960072601       ; Serial
300     ; Refresh - 5 minutes
60      ; Retry - 1 minute
38400   ; Expire - 2 weeks
43200 ) ; Minimum - 12 hours
IN      NS      ns.net.dlut.chinastor.com.
IN      NS      cedrus.dlut.chinastor.com.
;   Define localhost
;
localhost               IN      A               127.0.0.1
ns                      IN      A               202.118.65.1
IN      A               202.118.66.13
www                     IN      A               202.118.65.8
-----------------------------------------------------------------
  其中在SOA (Start of Authority)记录中的ns.net.dlut.chinastor.com. 为此文件
所在主机名(切记:完整的主机名最后应以点结束),hbwork.dlut.chinastor.com
为管理员Email地址hbwork@dlut.chinastor.com的变通形式,因@号在此文件
中代表当前授权域名,即/etc/named.boot相应记录中指定的域名net.dlut.chinastor.com
960072601为序列好,每更改一次此值应增加,备份域名服务器根据此值决定是否
应从主域名服务器请求新的数据;NS记录指定此域(net.dlut.chinastor.com)的两个域名
服务器,其中net.dlut.chinastor.com.的IP地址在下面由 A (address)记录给出,
cedrus.dlut.chinastor.com. 的IP地址由resolver从dlut.chinastor.com.域名服务器获得。
  在其后的A记录指明了相应主机的IP地址,如主机ns有两个IP地址。请注意主机
gw的完整名称为gw.net.dlut.chinastor.com. ,因为此名称不是以点结束,因此其主机名
将追加域名net.dlut.chinastor.com构成完整的主机名(fully qualified domain names)
当然在此文件中还有其他记录类型,如CNAME MX 等,具体请参考named文档,以下
仅给出简单示例:
   设定别名:如linux.dlut.chinastor.com 为主机ns.net.dlut.chinastor.com之别名,主机
gingko.dlut.chinastor.com有别名ftp.dlut.chinastor.com www.dlut.chinastor.com mail.dlut.chinastor.com
则在域dlut.chinastor.com的域名服务器的数据文件中使用如下记录:
    gingko                IN   A  202.118.66.8
ftp                   IN   CNAME gingko.dlut.chinastor.com.
www                   IN   CNAME gingko.dlut.chinastor.com.
mail                  IN   CNAME gingko.dlut.chinastor.com.
    linux.dlut.chinastor.com.    IN   CNAME  ns.net.dlut.chinastor.com.
   设定邮件交换MX(Mail Exchange)记录,如指定user@net.dlut.chinastor.com的邮件由主机
ns.net.dlut.chinastor.com接收,相应备份邮件服务器为gingko.dlut.chinastor.com,可使用如下记录
(当然相应主机的sendmail.cf应做适当调整):
   @       IN      SOA     ns.net.dlut.chinastor.com. hbwork.dlut.chinastor.com. (
960072601       ; Serial
300     ; Refresh - 5 minutes
60      ; Retry - 1 minute
38400   ; Expire - 2 weeks
43200 ) ; Minimum - 12 hours
IN      NS      ns.net.dlut.chinastor.com.
IN      NS      cedrus.dlut.chinastor.com.
IN      MX      1 ns.net.dlute.du.cn.  
IN      MX      10 gingko.dlut.chinastor.com. 
    MX之变通形式,如在此域名服务器上指定user@net.dlut.chinastor.com的邮件由
    ns.net.dlut.chinastor.com. 接收,也可使用如下形式之一:
    (1)
net.dlut.chinastor.com.   IN   A  202.118.65.1
    (2)
        net.dlut.edcu.cn.  IN   CNAME gw.net.dlut.chinastor.com.
    但不建议使用上面两种方式。

4. 建立文件/etc/namedb/db.202.118.65,本文件为进行反向查询(由IP查找域名)初始化
文件,文件内容列表如下:
;
; Data file for reverse address to hostname.
;
@       IN      SOA     ns.net.dlut.chinastor.com. hbwork.dlut.chinastor.com. (
960072601       ; Serial
300     ; Refresh - 5 minutes
60      ; Retry - 1 minute
1209600 ; Expire - 2 weeks
43200 ) ; Minimum - 12 hours
IN      NS      ns.net.dlut.chinastor.com.
IN      NS      cedrus.dlut.chinastor.com.
1.65.118.202.in-addr.arpa.      IN      PTR     ns.net.dlut.chinastor.com.

5.建立文件/etc/namedb/localhost.rev,内容如下:
;
; BIND data file for local loopback interface.
;
@       IN      SOA     ns.net.dlut.chinastor.com. hbwork.dlut.chinastor.com. (
96072601        ; Serial
3600    ; Refresh
300     ; Retry
3600000 ; Expire
3600 )  ; Minimum
IN      NS      ns.net.dlut.chinastor.com.
1       IN      PTR     localhost.
   更改ns.net.dlut.chinastor.com.为你的主机名,hbwork.dlut.chinastor.com.为你的
Email 地址。

6.创建文件/etc/namedb/root.cache,列出顶级域名服务器,内容如下:
.       99999999  NS      I.ROOT-SERVERS.NET.
.       99999999  NS      F.ROOT-SERVERS.NET.
.       99999999  NS      G.ROOT-SERVERS.NET.
.       99999999  NS      A.ROOT-SERVERS.NET.
.       99999999  NS      H.ROOT-SERVERS.NET.
.       99999999  NS      B.ROOT-SERVERS.NET.
.       99999999  NS      C.ROOT-SERVERS.NET.
.       99999999  NS      D.ROOT-SERVERS.NET.
.       99999999  NS      E.ROOT-SERVERS.NET.
;; ADDITIONAL RECORDS:
I.ROOT-SERVERS.NET.     99999999 A       192.36.148.17
F.ROOT-SERVERS.NET.     99999999 A       192.5.5.241
G.ROOT-SERVERS.NET.     99999999 A       192.112.36.4
A.ROOT-SERVERS.NET.     99999999 A       198.41.0.4
H.ROOT-SERVERS.NET.     99999999 A       128.63.2.53
B.ROOT-SERVERS.NET.     99999999 A       128.9.0.107
C.ROOT-SERVERS.NET.     99999999 A       192.33.4.12
D.ROOT-SERVERS.NET.     99999999 A       128.8.10.90
E.ROOT-SERVERS.NET.     99999999 A       192.203.230.10
  此文件不做任何改动既可使用,当然也可用实用程序dig取得最新顶级
域名服务器列表,方法如下:
   dig @ns.internic.net . ns

7.
(1) Slackware 3.x
    修改系统启动文件 /etc/rc.d/rc.inet2,去掉named部分的注释
(2) Redhat 5.x/6.x
    看一下系统中是否有如下文件:
/etc/rc.d/init.d/named以及/etc/rc.d/rc3.d/S*named
    如果没有建立文件/etc/rc.d/init.d/named, 文件内容如下:
#!/bin/sh
#
# named           This shell script takes care of starting and stopping
#                 named (BIND DNS server).
#
# chkconfig: 345 55 45
# description: named (BIND) is a Domain Name Server (DNS)
# that is used to resolve host names to IP addresses.
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/named ] || exit 0
[ -f /etc/named.conf ] || exit 0
# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting named: "
        daemon named
        echo
        touch /var/lock/subsys/named
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down named: "
        killproc named
        echo "done"
        rm -f /var/lock/subsys/named
        ;;
  status)
        status named
        exit $?
        ;;
  restart)
        /usr/sbin/ndc restart
        exit $?
        ;;
  *)
        echo "Usage: named {start|stop|status|restart}"
        exit 1
esac
exit 0
#End of /etc/rc.d/init.d/named
在/etc/rc.d/rc3.d/下建立相应的连接(确认没有文件S*named?)
#cd /etc/rc.d/rc3.d
#ln -s ../init.d/named S98named
(3)Debian 2.x
   如果你用的是Debian 2.x, 我想你肯定能修改相关的系统启动文件:)

8.确认文件/etc/host.conf文件host行内容如下:
   order hosts,bind

9.创建或编辑文件/etc/resolv.conf,指向新的域名服务器,内容如下:
  domain net.dlut.chinastor.com
  nameserver 202.118.65.1
  其中domain一行为你的域名,nameserver为你的域名服务器的IP地址。
  如在运行named或系统重新启动后域名不好用,可执行/sbin/netconfig,在域名
服务器配置部分输入新的域名及域名服务器IP地址,再重新启动机器。

10. DNS Client的配置
  (1) Unix 操作系统
编辑/etc/resolv.conf,参见服务器/etc/resolv.conf
  (2) Windows 95
      更改网络中TCP/IP的DNS设置
  (3) Novell Lan Workplace
      Sun PC-NFS
      FTP TCP/IP
      更改响应resolv.cfg 文件即可。

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。