- unbound:由于 dnsmasq 的性能可能较为低下,因此增加 unbound 作为缓存。
- dnsmasq:通过规则将 gfwlist 内的域名的解析转发给 dnscrypt 来处理。
- dnscrypt:穿越防火墙向 dnscrypt resolver 请求域名解析。
本文实验所使用的软件和版本
- FreeBSD 11.1-RELEASE-p4
- ezjail-3.4.2
- dnscrypt-proxy-1.9.5_3
- dnsmasq-2.78,1
- unbound-1.6.8
- bind-tools-9.11.2P1
使用了 ezjail 来管理 jails,dnscrypt(IP: 192.168.0.3)、dnsmasq(IP: 192.168.0.4)、unbound(IP: 192.168.0.5) 分别安装于独立的 jail 中。
bind-tools 提供了一组 DNS 工具,比如 nslookup、dig 等可用于测试。
dnscrypt 的安装与配置
pkg install dnscrypt-proxy
sysrc dnscrypt_proxy_enable=”YES”
sysrc dnscrypt_proxy_resolver=”ipredator”
service dnscrypt-proxy start
更多的 dnscrypt resolvers 可以从 /usr/local/share/dnscrypt-proxy/dnscrypt-resolvers.csv 里找到。
dnsmasq 的安装与配置
pkg install dnsmasq
sysrc dnsmasq_enable=”YES”
service dnsmasq start
修改 /usr/local/etc/dnsmasq.conf 确保其包含了下面的配置:
conf-dir=/usr/local/etc/dnsmasq.d/,*.conf
使用 gfwlist2dnsmasq.awk 定时更新 /usr/local/etc/dnsmasq.d/gfwlist.conf。在 /etc/crontab 里添加:
30 2 * * * root /usr/local/bin/gfwlist2dnsmasq.sh -h 192.168.0.3 -p 53 -S -u /usr/local/etc/user_rule.txt > /dev/null 2>&1
unbound 的安装与配置
pkg install unbound
sysrc unbound_enable=”YES”
service unbound start
在 /usr/local/etc/unbound/unbound.conf 内相应的位置添加如下配置:
access-control: 0.0.0.0/0 allow
forward-zone: name: . forward-addr: 192.168.0.4
修改后的配置文件的差异如下:
root@unbound:~ # diff -ruN /usr/local/etc/unbound/unbound.conf.sample /usr/local/etc/unbound/unbound.conf --- /usr/local/etc/unbound/unbound.conf.sample 2018-01-20 01:09:20.000000000 +0000 +++ /usr/local/etc/unbound/unbound.conf 2018-02-10 03:09:24.140462000 +0000 @@ -231,6 +231,7 @@ # access-control: ::0/0 refuse # access-control: ::1 allow # access-control: ::ffff:127.0.0.1 allow + access-control: 0.0.0.0/0 allow # tag access-control with list of tags (in "" with spaces between) # Clients using this access control element use localzones that @@ -807,6 +808,9 @@ # forward-zone: # name: "example.org" # forward-host: fwd.example.com +forward-zone: + name: . + forward-addr: 192.168.0.4 # Views # Create named views. Name must be unique. Map views to requests using
pf 的配置
转发到外部 IP 地址端口 53 的请求到 unbound 的 jail,示例配置:
rdr pass on $ext_if proto tcp from any to $ext_ip port 53 -> 192.168.0.5 rdr pass on $ext_if proto udp from any to $ext_ip port 53 -> 192.168.0.5
测试
dig +short @192.168.0.5
www.google.com
216.58.207.196