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

0%

Ubuntu14.04配置DNS Server

1. 前言

《Ubuntu系统批量自动安装》一文中,也许会用到DNS Server,那么就来研究配置一下。

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

2. 实践

2.1. 安装

安装命令:
sudo apt-get update

sudo apt-get install bind9

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

2.2. DNS正反解区域

1、添加DNS正反解区域,需要修改named.conf.default-zones

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并编辑
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并编辑
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.

2.3. 测试

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

2、重启dns服务
sudo /etc/init.d/bind9 restart

3、测试访问
ping dns.voidking.com
这次访问,就可以正常ping到服务器100的ip地址。

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

至此,DNS服务器已经配置成功。但是,我们本地的这个DNS服务器上存的域名太少了,比如ping www.baidu.com,就会ping不通。这时,我们需要配置转发服务器。

2.4. 配置转发服务器

1、编辑named.conf.options
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服务
sudo /etc/init.d/bind9 restart

3、测试访问
ping www.baidu.com

4、其他机器测试访问
同局域网主机在/etc/resolv.conf中添加:

1
nameserver 10.0.0.100

然后ping dns.voidking.comping www.baidu.com

3. 后记

至此,DNS Server安装配置成功,更高级的用法需要时再去学习。