install in debian

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apt-get install -y bind9
/etc/bind/named.conf # 主要include其他配置文件
/etc/bind/named.conf.options # 配置options
/etc/bind/* # 其他配置
/etc/bind/db* # dns解析的配置

named-checkconf # 检查配置
service bind9 restart # 启动服务
tail -f /var/log/syslog # 查看日志

# 测试工具需要本地安装 bind-utils:
apt install bind-utils # debian
apt install dnsutils # ubuntu

dig @127.0.0.1 example.com # 测试本机域名
dig @127.0.0.1 baidu.com # 测试外网解析

注意如果53端口被占用(比如在debian系中被systemd-resolved占用,systemd本身是做启动管理的,但是它野心大,什么都想插一脚。这不,给你默认加了一个本地dns缓存。)
我们来配置系统,关掉它。用路由器分配的dns就行了,或者我们自己来配置。

参考:https://www.cnblogs.com/xzlive/p/17139520.html

1
2
systemctl disable systemd-resolved
systemctl stop systemd-resolved

配置 conf

首先 /etc/bind/named.conf 文件是必须的,默认配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
# cat /etc/bind/named.conf
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local

include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

你可以自己定义多个配置文件,只要最终被include到/etc/bind/named.conf里面就行了。
基本的必须配置options:

1
2
3
4
5
6
7
8
9
10
11
12
$ cat /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
dnssec-validation auto;
forwarders {
8.8.8.8;
114.114.114.114;
0.0.0.0;
};
}

配置 dns解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ cat /etc/bind/named.conf.example.com
key "example.com-key" {
algorithm hmac-sha256; // 这里可以选择算法,hmac-算法
secret "你的秘钥";
};

zone "example.com" IN {
type master;
file "/etc/bind/db.example.com";
update-policy { // 更新政策,一域名一秘钥
grant example.com-key name example.com ANY;
};
};

ddns的使用

  1. 使用ddns需要本地安装 bind-utils,dig和nsupdate工具等
1
2
3
4
apt install bind-utils  # debian
apt install dnsutils # ubuntu

dig @vps02.hs3434.top example.com # 先测试一下解析是否成功
  1. 配置一个秘钥
1
2
3
4
5
$ cat mykey.key 
key "example.com-key" {
algorithm hmac-sha256;
secret "你的秘钥";
};
  1. 使用 nsupdate 测试是否可以更新dns
1
2
3
4
5
6
7
8
9
$ nsupdate -k mykey.key 
server vps02.hs3434.top
# key hmac-sha256:example.com-key 你的秘钥 # 没有秘钥文件时使用这个直接输入秘钥
update del example.com A
update add example.com 600 A 10.10.10.10
show
send
answer
quit