1. 程式人生 > >DNS BIND 搭建域名智慧解析DNS伺服器之動態新增解析

DNS BIND 搭建域名智慧解析DNS伺服器之動態新增解析

上一節我們講了關於bind的智慧解析的chroot配置,本節我們將通過指令碼來實現動態新增域名及解析記錄。

1.安裝bind

2.管理指令碼

指令碼都放在chroot/bin目錄下

管理指令碼./bin/slim-bind

./bin/slim-bind 
Usage:./bin/slim-bind start | stop | restart |reload |status
管理bind的啟動、關閉、重啟、重新載入配置、狀態。

3.檢查指令碼

1)檢查zone檔案是否有效

./bin/slim-checkzone -h
usage: ./bin/slim-checkzone [-z zone -f zonefile] [-h]
    z   zone name
    f   zone file
    h   output this help and exit
說明:

z 指定zone名稱

f 指定zone的檔案

2)檢查named.conf是否正確

./bin/slim-checkconf -h
usage: ./bin/slim-checkconf named.conf [-h]
    h   Output this help and exit
The named.conf file is relatvie to "chroot",such as /etc/named.conf.
By using chroot, you must use the root user. 
由於使用了chroot,使用該指令碼必須使用root許可權,指定的named.conf是chroot的相對路徑。
如:./bin/slim-checkconf /etc/named.conf

4.新增刪除域名指令碼

./bin/slim-zone-randfs -h
usage: ./bin/slim-zone-randfs  [-s server -p port -o [r|a|n|d|f|s] -v view -z zone -f zonefile] [-h]
command is one of the following:
    s   bind server ip(default:127.0.0.1)
    p   bind server port(default:953)
    o   operation type
        r       reload configuration file and zones.
        a       add zone to given view. Requires new-zone-file option.
        n       resend NOTIFY messages for the zone.
        d       removes zone from given view.
        f       flushes the server's caches for a view or zone.
        s       display status of the server.
    v   view name
    z   zone name
    f   zone file
    h   Output this help and exit
when the zone doesn't exit,we can call the rndc to add the zone dynamicly,which 'view' 'zone' 'zonefile' must be used.
the zonefile is relatvie to "chroot",such as /var/named/zone/test.com.zone.
該指令碼可以動態新增、刪除域名、載入配置、重新整理快取,以及檢視bind狀態

說明:

s  指定bind伺服器IP地址,預設是127.0.0.1

p  指定rndc啟動埠,預設是953

o  執行操作型別,主要有如下幾種型別:

   r 載入配置

   a 新增域名 

   n 重新發送notify訊息

   d 刪除域名

   f 重新整理快取

   s 檢視狀態
v  所操作的檢視

z  所操作的zone 名稱

f  所操作的zone檔案

5.新增刪除解析記錄指令碼

./bin/slim-rdata-ad -h
usage: ./bin/slim-rdata-ad [-s server -p port -o [a|d] -v view -r rdata ] [-h]
    s   bind server ip(default:127.0.0.1)
    p   bind server port(default:53)
    o   operation type
        a  add zone record
        d  delete zone record
    v   view name
    r   zone rdata string,such as "www.slimsmart.cn 3600 IN A 1.1.1.1"
    h   output this help and exit
該指令碼動態向每個檢視新增域名的解析記錄。

說明:

s  指定bind伺服器IP地址,預設是127.0.0.1

p  指定rndc啟動埠,預設是953

o  執行操作型別,主要有如下幾種型別:

   a 新增解析記錄

   d 刪除解析記錄

v  所操作的檢視

r  解析記錄值rdata

大家可以利用這些指令碼,動態新增域名解析,也可以開發web管理頁面,方便維護管理。