本文在 Ubuntu 16.04 版本中使用 BIND9 搭建出一个可用的内网 DNS 服务。另外要说明的一点是,本文不仅适用于 Ubuntu 16.04,也适用于 Ubuntu server 18.04 或者其它的 Ubuntu 版本,至于 18.04 之后如 Ubuntu 18.10 尚未测试,不保证也能适合。下面是配置极简内网 DNS 服务的重要操作步骤。
1.安装 BIND9
先更新 APT,之后再安装 BIND9 相关的软件包:
$ sudo apt update
$ sudo apt install bind9 bind9utils bind9-doc
2.配置 BIND9 的 IPv4 模式
这步是要将 BIND9 设置为只支持 IPv4 地址,如果需要用到 IPv6 地址的话,可以跳过这步。
我们需要修改 BIND9 的 systemd unit file:
$ sudo systemctl edit --full bind9
当然我们也可以直接用文件编辑器修改文件:
$ sudo vim /etc/systemd/system/multi-user.target.wants/bind9.service
文件内容如下,在 ExecStart 这行的最后加上 -4 就可以了。
...
[Service]
...
ExecStart=/usr/sbin/named -f $OPTIONS -4
...
修改配置后,需要重启 BIND9,因为 systemd 的 unit file 也变了,所以需要重新载入:
$ sudo systemctl daemon