FreeBSD自带local_unbound,默认情况下,仅向本地系统提供DNS解析。
若要提供完整的DNS服务,可使用unbound。
在/etc/rc.conf文件中加入以下行:
xxxxxxxxxxlocal_unbound_enable="YES"local_unbound服务启动时会修改/etc/resolv.conf文件,屏蔽掉以前设置的nameserver,并加入以下两行:
xxxxxxxxxxnameserver 127.0.0.1options edns0
edns是RFC2671提出的一种扩展DNS机制,EDNS(Extension Mechanisms for DNS),并在其中推荐了一种传递包大小的EDNS0。
原来的/etc/resolv.conf文件被保存为/etc/resolv.conf.bak文件。且生成了一个新文件/etc/resolvconf.conf,内容如下:
xxxxxxxxxx# This file was generated by local-unbound-setup.# Modifications will be overwritten.resolv_conf="/dev/null" # prevent updating /etc/resolv.confunbound_conf="/var/unbound/forward.conf"unbound_pid="/var/run/local_unbound.pid"unbound_service="local_unbound"unbound_restart="service local_unbound reload"从上述内容可知,配置文件保存在/var/unbound目录中。
此目录初始一共有四个conf文件、一个key文件,以及一个名为conf.d的空目录。
以上所有.conf文件的头部都有提示,任何修改都会被覆写。所以如果要进行设置,建议在conf.d目录中单独创建配置文件,例如:
xxxxxxxxxxauth-zone: name: "." primary: 199.9.14.201 # b.root-servers.net primary: 192.33.4.12 # c.root-servers.net primary: 199.7.91.13 # d.root-servers.net primary: 192.5.5.241 # f.root-servers.net primary: 192.112.36.4 # g.root-servers.net primary: 193.0.14.129 # k.root-servers.net primary: 192.0.47.132 # xfr.cjr.dns.icann.org primary: 192.0.32.132 # xfr.lax.dns.icann.org primary: 2001:500:200::b # b.root-servers.net primary: 2001:500:2::c # c.root-servers.net primary: 2001:500:2d::d # d.root-servers.net primary: 2001:500:2f::f # f.root-servers.net primary: 2001:500:12::d0d # g.root-servers.net primary: 2001:7fd::1 # k.root-servers.net primary: 2620:0:2830:202::132 # xfr.cjr.dns.icann.org primary: 2620:0:2d0:202::132 # xfr.lax.dns.icann.org fallback-enabled: yes for-downstream: no for-upstream: yes*以上来自delphij的blog:在本地架设根DNS的镜像
保存后重新加载local_unbound服务:
xxxxxxxxxx# service local_unbound reload以下是Root Servers (iana.org)的根服务器列表
xa.root-servers.net 198.41.0.4, 2001:503:ba3e::2:30 Verisign, Inc.b.root-servers.net 170.247.170.2, 2801:1b8:10::b University of Southern California,Information Sciences Institutec.root-servers.net 192.33.4.12, 2001:500:2::c Cogent Communicationsd.root-servers.net 199.7.91.13, 2001:500:2d::d University of Marylande.root-servers.net 192.203.230.10, 2001:500:a8::e NASA (Ames Research Center)f.root-servers.net 192.5.5.241, 2001:500:2f::f Internet Systems Consortium, Inc.g.root-servers.net 192.112.36.4, 2001:500:12::d0d US Department of Defense (NIC)h.root-servers.net 198.97.190.53, 2001:500:1::53 US Army (Research Lab)i.root-servers.net 192.36.148.17, 2001:7fe::53 Netnodj.root-servers.net 192.58.128.30, 2001:503:c27::2:30 Verisign, Inc.k.root-servers.net 193.0.14.129, 2001:7fd::1 RIPE NCCl.root-servers.net 199.7.83.42, 2001:500:9f::42 ICANNm.root-servers.net 202.12.27.33, 2001:dc3::35 WIDE Project
iocage默认设置,jail使用宿主机的/etc/resolv.conf文件作为自己的resolv配置。
但是local_unbound会修改宿主机的/etc/resolv.conf文件,将nameserver指向127.0.0.1,这就造成jail中的resolv.conf文件中nameserver也指向127.0.0.1。jail将无法获得正确的DNS解析。
解决方法分为两步:
xxxxxxxxxx/var/unbound/unbound.conf......interface: 192.168.0.101access-control: 192.168.0.0/24 allow做完以上设置后,重启local_unbound和iocage服务即可。