DNS设定实例
 
环境:
redhat9 :默认集成bind-9.2.1-16
功能:
内部使用的DNS,也可以访问外网的域名.
需求:
域名
主机名
IP
domain1.com
s1.domain1.com
192.168.0.111
s2.domain1.com
192.168.0.111
domain2.com
s3.domain2.com
192.168.0.111
s4.domain2.com
192.168.0.28
正向文件 domain1.com 对应 domain1.com.zone;domain2.com 对应 domain2.com.zone
反向文件 0.168.192.local
实验就将192.168.0.111作为dns服务器,192.168.0.28作为客户端
 
配置文件如下
/etc/named.conf
 
// generated by named-bootconf.pl
options {
     directory "/var/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;
     forwarders {
                202.103.24.68;
     };
        pid-file "/var/run/named/named.pid"; 
};
// 使得外部域名向外转发到202.103.24.68查询(武汉电信的DNS)
//
// a caching only nameserver config
//
controls {
     inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
zone "." IN {
     type hint;
     file "named.ca";
};
 
zone "localhost" IN {
     type master;
     file "localhost.zone";
     allow-update { none; };
};
 
zone "0.0.127.in-addr.arpa" IN {
     type master;
     file "named.local";
     allow-update { none; };
};
 
 
zone "domain1.com" IN {
     type master;
     file "domain1.com.zone";
     allow-update { none; };
};
 
zone "domain2.com" IN {
     type master;
     file "domain2.com.zone";
     allow-update { none; };
};
 
zone "0.168.192.in-addr.arpa" IN {
     type master;
     file "0.168.192.local";
     allow-update { none; };
};
include "/etc/rndc.key";
 
/var/named/domain1.com.zone
 
$TTL 86400
$ORIGIN domain1.com.
@        1D IN SOA      localhost. root (
                       42       ; serial (d. adams)
                       3H       ; refresh
                       15M      ; retry
                       1W       ; expiry
                       1D )     ; minimum
 
              1D IN NS localhost.
s1            1D IN A       192.168.0.111
s2            1D IN A       192.168.0.111
 
/var/named/domain2.com.zone
 
$TTL    86400
$ORIGIN domain2.com.
@           1D IN SOA   localhost. root (
                    42      ; serial (d. adams )
                    3H      ; refresh
                    15M     ; retry
                    1W      ; expiry
                    1D )        ; minimum
 
            1D IN NS    localhost.
s3          1D IN A     192.168.0.111
s4          1D IN A     192.168.0.28
 
/var/named/0.168.192.local
 
$TTL         86400
@       IN      SOA     localhost. root.localhost.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
              IN      NS      localhost.
 
111       IN      PTR     s1.domain1.com.
111       IN      PTR     s2.domain1.com.
111       IN      PTR     s3.domain2.com.
28       IN      PTR     s4.domain2.com.
 
启动服务
/etc/rc.d/init.d/named start
 
port 观察
[root@test root]# netstat -tuln | grep 53
 
查看日志
tail -n 15 /var/log/messages | grep named
 
在设定好之后,方便直接在dns服务器调试,需要改本机的DNS,可以这么改
[root@localhost named]# vi /etc/resolv.conf
 
nameserver 127.0.0.1
nameserver 202.103.24.68
search localdomain
 
客户端测试,XP上将DNS指向192.168.0.111
ping如下地址
s1.domain1.com
s2.domain1.com
s3.domain2.com
s4.domain2.com
[url]www.baidu.com[/url] ( 外网域名)
 
所有通过表示成功