如何使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值