Bind是使用最广泛的DomainName Server,它是Berkeley Internet Name Domain Service的简写,伯克里大学编写的。在Debian Stretch 9.3中,它的最新版本是Bind 9.10.5。
安装 Bind 比较简单,使用如下命令即可,
apt-get install bind9
apt-get install bind9-host dnsutils
apt-get install bind9-doc
配置 Bind,有以下步骤,
1,域名解析 这里以将 debian.cn 解析到192.168.10.2为例:
cd /etc/bind
vim named.conf.local
增加正向解析和反向解析区域(zone):
zone "debian.cn" {
type master;
file "/etc/bind/db.debian.cn";
};
zone "168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168";
};
1.1 正向解析:db.debian.cn内容如下:
(adsbygoogle = window.adsbygoogle || []).push({});
$TTL 604800
@ IN SOA debian.cn. admin.debian.cn. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.debian.cn.
@ IN A 192.168.10.2
ns IN A 192.168.10.2
www IN CNAME @
ftp IN CNAME @
proxy IN CNAME @
blog IN CNAME @
mysql IN CNAME @
* IN A 192.168.10.2
这里指定了域 debian.cn 的授权 DNS服务器为 ns.debian.cn. 即为本机,因为随后的正向解析记录(即A记录),将 ns 指向到了本地的IP地址 192.168.10.2。 同时我们也添加了几个 CNAME 别名记录,都指向 debian.cn。 最后添加泛解析支持,所有对 *.debian.cn 的請求都会被解析到192.168.10.2 。 1.2 反向解析:db.192.168内容如下:
$TTL 604800
@ IN SOA debian.cn. admin.debian.cn. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.debian.cn.
2.1 IN PTR debian.cn.
这里的反向解析很简单,就是将 192.168.10.2 指向 debian.cn
2. 配置cache(缓存)dns服务器
vim named.conf.options
去掉其中几个注释符号(//) ,添加你所在网络的ISP (internet 信息服务提供商)的DNS 。最后内容如下:
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
forwarders {
114.114.114.114;
61.139.2.69;
};
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};
3. 重启BIND服务
使用命令 sudo systemctl restart bind9 或者 sudo rndc reload
4. 测试BIND解析是否正常
使用测试命令,确认百度主站是否能正确解析,
dig www.baidu.com @192.168.10.2
注意 @192.168.10.2 目的是指定我们使用的域名服务器。由于上面我们在 resolv.conf 中指定了本机使用的DNS服务器为 192.168.10.2, 所以在这里 @192.168.10.2 不是必须的。
至此,配置结束,更信息的说明请仔细阅读Debian官网的Bind9页面。