Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

使用 bind 建置 DNS 伺服器實驗

實驗環境

作業系統為 RHEL 5.6,共三台主機:hotel01(192.168.2.111)擔任 server,hotel02(192.168.2.112)與 hotel03(192.168.2.113)為 client。DNS 服務架在 hotel01 上,負責解析這三台主機的主機名稱。

一、安裝 bind

由於使用的是未註冊的 OEL 版本,yum 無法線上安裝,需從光碟掛載後手動安裝 bind 與 caching-nameserver 相關套件:

[root@hotel01 ~]# rpm -qa|grep bind
bind-utils-9.3.6-16.P1.el5
bind-chroot-9.3.6-16.P1.el5
bind-9.3.6-16.P1.el5
bind-libs-9.3.6-16.P1.el5

[root@hotel01 ~]# rpm -qa|grep caching-nameserver
caching-nameserver-9.3.6-16.P1.el5

二、修改主設定檔

使用 chroot 時,設定檔都位於 /var/named/chroot/ 底下,named.conf 在 etc 子目錄,區域檔在 var/named 子目錄。

[root@hotel01 etc]# cp -p named.caching-nameserver.conf named.conf
[root@hotel01 etc]# vi named.conf

options {
    listen-on port 53 { any; };      // 把 127.0.0.1 改成 any
    listen-on-v6 port 53 { ::1; };
    directory "/var/named";
    allow-query { any; };
    allow-query-cache { any; };
};

view localhost_resolver {
    match-clients { any; };          // 把 localhost 改成 any
    match-destinations { any; };     // 同上
    recursion yes;
    include "/etc/named.rfc1912.zones";
};

三、定義區域

[root@hotel01 etc]# vi named.rfc1912.zones

zone "licz.com" IN {
    type master;
    file "licz.com.zone";
    allow-update { none; };
};

zone "2.168.192.in-addr.arpa" IN {
    type master;
    file "2.168.192.in-addr.zone";
    allow-update { none; };
};

四、建立區域檔

[root@hotel01 named]# cp -p localdomain.zone chroot/var/named/licz.com.zone
[root@hotel01 named]# cp -p named.local chroot/var/named/2.168.192.in-addr.zone

正向區域檔內容:

$TTL 86400
@ IN SOA localhost root (
    42      ; serial
    3H      ; refresh
    15M     ; retry
    1W      ; expiry
    1D )    ; minimum
  IN NS localhost

hotel01 IN A 192.168.2.111
hotel02 IN A 192.168.2.112
hotel03 IN A 192.168.2.113

反向區域檔內容:

$TTL 86400
@ IN SOA localhost. root.localhost. (
    1997022700 ; Serial
    28800      ; Refresh
    14400      ; Retry
    3600000    ; Expire
    86400 )    ; Minimum
  IN NS localhost.

111 IN PTR hotel01.licz.com
112 IN PTR hotel02.licz.com
113 IN PTR hotel03.licz.com

五、修改各節點的 resolv.conf

[root@hotel01 named]# vi /etc/resolv.conf
nameserver 192.168.2.111

hotel02 與 hotel03 也做同樣設定,指向 DNS 伺服器。

六、驗證測試

[root@hotel01 etc]# nslookup
> hotel01.licz.com
Name:    hotel01.licz.com
Address: 192.168.2.111
> hotel02.licz.com
Address: 192.168.2.112
> hotel03.licz.com
Address: 192.168.2.113

再用 ping 以主機名稱測試連通性:

[root@hotel01 named]# ping hotel03.licz.com
PING hotel03.licz.com (192.168.2.113) 56(84) bytes of data.
64 bytes from hotel03 (192.168.2.113): icmp_seq=1 ttl=64 time=10.8 ms
64 bytes from hotel03 (192.168.2.113): icmp_seq=2 ttl=64 time=0.360 ms

正反向解析都正確,DNS 建置完成。

Copyright © Linux教程網 All Rights Reserved