您的位置:首页 > 其它

用unbound搭建简单的DNS服务器

2017-03-02 16:48 183 查看
unbound是一款相对简单的DNS服务软件,相对于bind9的复杂配置,更适合新手搭建DNS服务器使用。
话不多说,下面介绍一下unbound的配置。
截止笔者写这篇文章时,unbound已经更新到1.6.1版本。本例所用环境如下:
linux服务器为:Ubuntu 14.04;
unbound软件版本为:1.6.0。
以下为具体安装过程:
1.安装依赖包:
#CentOS系统:
sudo yum -y install gcc openssl-devel expat-devel libevent-devel
#ubuntu系统:
sudo apt-get install gcc openssl libssl-dev libexpat1-dev libevent-dev
2.下载unbound软件
#官方下载地址:
https://unbound.net/download.html
3.编译安装
./configure --prefix=/usr/local/unbound --with-pthreads  --with-libevent --with-ssl
参数说明:
--with-pthreads:支持多线程;
--with-libevent:允许使用大的传出端口范围。
--with-ssl:用于生成秘钥文件
4.配置unbound.conf文件
server:
verbosity: 1
num-threads: 2  #线程数
interface: 127.0.0.1 #监听地址(一般写本机内网ip)
interface: ::0
port: 53  #端口
so-reuseport: yes  #为每个线程的传入查询打开专用侦听套接字。可以更均匀地将传入查询分布到线程
cache-min-ttl: 60  #解析最小缓存时间
cache-max-ttl: 600 #解析最大缓存时间
outgoing-range: 8192
access-control: 10.0.0.0/8 allow  #访问控制(允许10段ip访问本机)
access-control: 127.0.0.1/8 allow  #允许本机访问
access-control: ::0/0 allow  #允许ipv6网段访问
prefetch: yes    #消息缓存元素在它们到期之前被预取以保持缓存是最新的
do-ip4: yes
do-ip6: yes
do-udp: yes
do-tcp: yes
so-rcvbuf: 8m
so-sndbuf: 8m
msg-cache-size: 64m   #消息缓存的字节数。 默认值为4 MB。
rrset-cache-size: 128m   #RRset缓存的字节数。
outgoing-num-tcp: 256   #为每个线程分配的传出TCP缓冲区数
incoming-num-tcp: 1024   #为每个线程分配的传入TCP缓冲区数
include: "zone.conf"   #zone.conf文件内容为解析内容,如local-data: "m.baidu.com A 192.168.10.1",也可以使用下面注释的方式配置解析
#        local-data: "m.baidu.com 600 A 192.168.10.1"  #其中600为解析缓存时间
#python:
remote-control:    #这个区间为unbound控制设置。配置如下内容可以控制unbound服务,利用unbound-control命令对该服务执行开启、关闭、重启等操作。
control-enable: yes
control-interface: 127.0.0.1
control-port: 8953
server-key-file: "/usr/local/unbound/etc/unbound/unbound_server.key"
server-cert-file: "/usr/local/unbound/etc/unbound/unbound_server.pem"
control-key-file: "/usr/local/unbound/etc/unbound/unbound_control.key"
control-cert-file: "/usr/local/unbound/etc/unbound/unbound_control.pem"
forward-zone:     #这个区间为转发设置
name: "."
forward-addr: 8.8.8.8
5.启动服务
首先执行./sbin/unbound-checkconf检查配置文件语法,确认无误后进行下一步;
执行/sbin/unbound-control-setup生成秘钥,之后才能使用/sbin/unbound-control命令;
最后执行./sbin/unbound启动服务。
6.测试解析结果
$ dig m.baidu.com @127.0.0.1
; <<>> DiG 9.9.5-3ubuntu0.4-Ubuntu <<>> m.taobao.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61026
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;m.baidu.com.                  IN      A
;; ANSWER SECTION:
m.baidu.com.           600     IN      A       192.168.10.1
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Mar 02 16:39:50 CST 2017
;; MSG SIZE  rcvd: 46
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dns A记录 解析 unbound