Centos7搭建unbound(dns)服务器

华盟原创文章投稿奖励计划

之前搭建DNS服务器特别麻烦,偶然发现这个搭建特别简单


一、环境:

centos7

二、解析:

DNS服务器有多种软件可以实现,这次用的是unbound简单的使用介绍
unbound配置文件:/etc/unbound/unbound.conf
DNS解析文件为:/etc/unbound/local.d/*.conf
本机DNS解析地址:/etc/resolv.conf

三、安装过程:


1.安装unbound服务软件
[root@darling ~]# yum install unbound -y
2.启动unbound服务,并设置开机自启
[root@darling ~]# systemctl start unbound

[root@xserver ~]# systemctl enable unbound
Created symlink from /etc/systemd/system/multi-user.target.wants/unbound.service to /usr/lib/systemd/system/unbound.service.

3.查看unbound状态
systemctl status unbound
查看dns侦听端口 netstat -tunlp | grep unbound
4.修改配置文件/etc/unbound/unbound.conf
将# interface: 0.0.0.0 的注释去掉,即改为:interface: 0.0.0.0
将# access-control: 0.0.0.0/0 refuse 的注释去掉,并将refuse改成allow。即access-control: 0.0.0.0/0 allow。
保存退出
5.自己编写一个dns解析文件,注意必须是这种格式/etc/unbound/local.d/*.conf
[root@darling~]# vim /etc/unbound/local.d/xdns.conf
local-zone: "Zer02.com." static
local-data: "Zer02.com. 3600 IN SOA darling.Zer02.com. root 1 1D 1H 1W 1H"
local-data: "darling.Zer02.com.        IN A 195.134.1.66"
local-data-ptr: "195.134.1.66 darling.Zer02.com."
local-data-ptr: "195.134.1.66 www.Zer02.com."

6.重启dns服务
systemctl restart unbound

这样基本就搭建好了


但是有时候会出几个问题


1.unbound没有启动

解决方法:
查看dns的53端口啥情况
netstat -ntulp | grep 53
unbound服务命名是失败的,但是53端口还是开启了
这时需要杀死dns进程然后重启unbound服务就好了


2.本机dns解析文件没改
解决方法:
修改解析文件,把dns地址改成本机ip
vim /etc/resolv.conf
# /etc/resolv.confnameserver 195.134.1.66

此时就可以ping通或者nslookup解析一下。
至于添加其他主机的dns,就可以照葫芦画瓢往配置文件里加就行了。有一点要注意啊,其他主机的dns指向必须指向这次配置的unbound主机才行。

至此unbound(dns)服务器就搭建完了。

本文原创,作者:congtou,其版权均为华盟网所有。如需转载,请注明出处:https://www.77169.net/html/271996.html

发表评论