一个计算机技术爱好者与学习者

0%

Ubuntu14.04安装配置DNS服务

1. 前言

《Ubuntu系统批量自动安装》一文中,用到了DNS服务,本文中我们来学习安装配置一下。

配置目标:在Ubuntu14.04上搭建一个DNS服务器,服务器地址为10.0.0.100。使用这个DNS,可以把dns.voidking.com域名解析到10.0.0.100这个地址。

参考文档:BIND官网

2. 安装DNS服务

安装命令:

1
2
sudo apt-get update
sudo apt-get install bind9

安装完成后,会创建/etc/bind目录,里面有很多配置文件。

3. 配置DNS正反解区域

1、添加DNS正反解区域

1
sudo vim /etc/bind/named.conf.default-zones

在最后添加:

1
2
3
4
5
6
7
8
9
zone "voidking.com" {
type master;
file "/etc/bind/db.voidking.com";
};

zone "0.0.10.in-addr.arpa" {
type master;
file "/etc/bind/db.10.0.0";
};

添加正解区域“voidking.com”,以及反解区域“10.0.0.0”

2、创建 db.voidking.com 配置文件

1
2
3
cd /etc/bind
sudo cp db.local db.voidking.com
sudo vim db.voidking.com

添加一个A记录到10.0.0.100:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
@ IN A 127.0.0.1
@ IN AAAA ::1
dns IN A 10.0.0.100

3、创建 db.10.0.0 配置文件

1
2
sudo cp db.127 db.10.0.0
sudo vim db.10.0.0

添加100的反向解析到dns.voidking.com:

1
2
3
4
5
6
7
8
9
10
11
12
13
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS voidking.com.
100 IN PTR dns.voidking.com.

4. 测试使用DNS服务

1、测试访问

1
ping dns.voidking.com

这次访问会提示 connection timed out: no servers could be reached,或者提示 ping: unknown host dns.voidking.com

2、重启dns服务

1
sudo /etc/init.d/bind9 restart

3、测试访问

1
ping dns.voidking.com

这次访问,就可以正常ping到服务器100的ip地址。

host 10.0.0.100,可以看到10.0.0.100绑定到了dns.voidking.com。

至此,DNS服务器已经配置成功。

5. 配置上游DNS服务器

自建的DNS服务器无法解析的查询请求,会进行递归查询。DNS具体解析流程,可以参考《DNS入门篇

此时,我们可以配置指定的上游DNS服务器,如果自建DNS服务器无法解析,那么会将该查询请求转发到指定的上游DNS服务器。上游DNS服务器将尝试解析该查询,并返回答案给自建DNS服务器。自建DNS服务器接收到上游DNS服务器的响应后,将答案返回给发起原始查询的客户端。
这样就可以让上游DNS服务器进行递归查询,从而减少自建服务器的递归查询数量,提高性能。

具体配置方法为:

1、编辑named.conf.options

1
sudo vim named.conf.options

forwarders设置转发DNS为180.76.76.76,allow-query设置为0.0.0.0/0:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
options {
directory "/var/cache/bind";

// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113

// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.

forwarders {
180.76.76.76;
};

allow-query {
0.0.0.0/0;
};

//========================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys. See https://www.isc.org/bind-keys
//========================================================================
dnssec-validation auto;

auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};

2、重启DNS服务

1
sudo /etc/init.d/bind9 restart

3、测试访问

1
ping www.baidu.com

6. 其他主机使用DNS服务

1、添加DNS配置
同局域网主机在 /etc/resolv.conf 中添加:

1
nameserver 10.0.0.100

2、测试使用DNS服务
然后ping dns.voidking.comping www.baidu.com

至此,DNS Server安装配置完成。

  • 本文作者: 好好学习的郝
  • 原文链接: https://www.voidking.com/dev-ubuntu-dns-server/
  • 版权声明: 本文采用 BY-NC-SA 许可协议,转载请注明出处!源站会即时更新知识点并修正错误,欢迎访问~
  • 微信公众号同步更新,欢迎关注~