Unbound 是一款强大的 DNS 服务,官网,提供 非标端口 && 本地缓存 && 强制 TCP 查询 等功能。本文讲述它的基本配置方法。
编译安装
强烈建议使用编译安装:
# 编译依赖 apt-get install -y build-essential && apt-get build-dep -y unbound # 编译开始 wget https://www.unbound.net/downloads/unbound-1.6.8.tar.gz && tar -zxf unbound-1.6.8.tar.gz cd unbound-1.6.8 ./configure --prefix=/home/unbound --sysconfdir=/home/unbound/etc --with-pidfile=/home/unbound/pid/unbound.pid --with-libevent --disable-rpath make && make install
配置文件
编译安装完成后,找到配置文件 /home/unbound/etc/unbound/unbound.conf
,修改它,参考以下说明写入你的配置:
# server 段 # 指定服务的配置项 server: chroot: "" username: "root" directory: "/home/unbound/sbin" pidfile: "/home/unbound/pid/unbound.pid" #监听地址。如果要作为公共服务,设置为 0.0.0.0;如果要仅本地使用,设置 127.0.0.1 interface: 127.0.0.1 #监听端口。你随意 port: 52 do-ip4: yes do-ip6: no do-tcp: no #提示:就算是强制 tcp 查询,也要在这里允许 do udp do-udp: yes #强制使用 tcp 查询上游 tcp-upstream: no #限制每个线程向上级查询的 TCP 并发数 outgoing-num-tcp: 100 #限制每个线程接受查询的 TCP 并发数 incoming-num-tcp: 100 #线程数,建议修改为物理核心数 num-threads: 2 #如果开了多线程,就写 yes so-reuseport: yes so-rcvbuf: 4m so-sndbuf: 4m msg-cache-size: 60m rrset-cache-size: 120m cache-max-ttl: 3600 cache-min-ttl: 600 #最小化响应,用于节省带宽。建议开启。若仅用于本地可以关闭 minimal-responses: yes #不查询 localhost(本地) do-not-query-localhost: no #禁用 DNSSEC 检查,如果上游不支持 DNSSEC 就启用这行。反之就注释掉 module-config: "iterator" #不返回对 id.server 和 hostname.bind 的查询 hide-identity: yes #不返回对 version.server 和 version.bind 的查询 hide-version: yes # forward 段 # 指定上游服务器 forward-zone: # 上游 1 #所有域名 name: "." #上游服务器的 [email protected] forward-addr: [email protected] # 上游 2 #指定具体的域名 name: "google.com" #上游服务器的 [email protected] forward-addr: [email protected]
启动服务
修改完成配置后,就可以运行主服务了
cd /home/unbound/sbin chmod +x unbound ./unbound
搭配其它 DNS 相关服务
例如说你想搭配 unbound + dnscrypt 组合,那么你就把 dnscrypt 放到 53 端口,然后这样指定 unbound 的上游:
forward-zone: name: "." forward-addr: [email protected]
并且,我在之前的文章 dingo – HTTPS DNS 服务 中也提到过其和 unbound 的搭配,道理同上。
转载请注明:逗比根据地 » Unbound – 强大的 DNS 服务