如何使用Docker搭建私有的DNSServer

編譯

git clone https://github.com/fyec/dns-docker.git
cd dns-docker
docker build -t dns .

配置

我們假設會建立repos.rd這個域名爲例, IP爲 218.8.7.6,配置文件在 /path/to/dns-docker/config/bind的路徑下。

db.rd

;
; BIND data file for local loopback interface
;
$TTL    86400
@   IN  SOA ns.rd. root.rd. (
             2014032802     ; Serial
             604800     ; Refresh
              86400     ; Retry
            2419200     ; Expire
             604800 )   ; Negative Cache TTL
;
@   IN  NS  ns.rd.
@   IN  A   218.8.7.6
ns  IN  A   218.8.7.6
www IN  A   218.8.7.6
repos   IN      A   218.8.7.6

db.218.8.7

;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA     ns.rd. root.rd. (
                     2014032801         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@     IN      NS      ns.rd.
6     IN      PTR     ns.rd.
6     IN      PTR     www.rd.
6     IN      PTR     repos.rd.

named.conf.options

options {
        directory "/etc/bind/cache";
        forwarders {
                8.8.8.8;
                8.8.4.4;
                114.114.114.114;
        };

        allow-query { any; };
        allow-query-cache { any; };
        dnssec-validation auto;
        allow-transfer  { none; };
        auth-nxdomain no;    # conform to RFC1035
        listen-on-v6 { any; };
};

named.conf.local

zone "rd" {
        type master;
        file "/etc/bind/db.rd";
};

zone "7.8.218.in-addr.arpa" {
        type master;
        file "/etc/bind/db.218.8.7";
};

運行

docker run -d -v /path/to/dns-docker/config/bind:/etc/bind -p 53:53 -p 53:53/udp dns

客戶端配置

將 218.8.7.6 作爲nameserver放到 /etc/resolv.conf 文件裏,我們也可以在路由器裏配置相關的信息,這樣整個局域網的用戶就都可以不做任何配置就可以使用這個DNS服務了。

檢查

$ nslookup repos.rd
Server:     218.8.7.6
Address:    218.8.7.6

Name:   repos.rd
Address: 218.8.7.6

其他問題

如果在配置過程中遇到 rndc.key 的問題, 可參考 
http://tecadmin.net/configure-rndc-for-bind9/
http://wujunfeng.blog.51cto.com/3041/1012409

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章