Ubuntu Server 18.04 DNS服务搭建记录

操作系统:Ubuntu Server 18.04

DNS_server_IP : 192.168.1.10

一.安装bind9

sudo apt update
sudo apt install bind9 bind9utils

二.修改配置

1.修改IPv4模式【OPTIONS参数增加 “-4” 】

dev@dns_server:/etc/default$ vim /etc/default/bind9 
#
# run resolvconf?
RESOLVCONF=no

# startup options for the server
OPTIONS="-u bind -4"

....

# 改后重启bind9服务
sudo systemctl restart bind9

2.修改named.conf.options配置文件

bind9配置文件named.conf 配置文件详解及使用术语

dev@dns_server:/etc/bind$ cat named.conf.options 
# 定义名为"trusted"的IP地址匹配列表
acl "trusted" {
    192.168.1.10; # DNS_server_ip
    192.168.0.10; # window客户端IP
};
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.
	# 设置递归查询
	recursion yes;
	# 允许acl规则的主机递归查询
	allow-recursion { trusted; };
	# DNS转发器
	forwarders {
	 	202.96.134.133;
	 	114.114.114.114;
	 	223.5.5.5;
	 	223.6.6.6;
	};
	allow-transfer { none; };

	//========================================================================
	// 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; };
};

参数详解:

  • acl :定义命名的 IP 地址匹配列表,用于访问控制和其他用途

  • recursion: 用于设置递归查询,一般客户机和服务器之间属于递归查询,即当客户机向DNS服务器发出查询请求后,若DNS服务器本身不能解析,则会向另外的DNS服务器发出查询请求,得到结果后转交给客户机。此选项有yesno两个值。

  • allow-recursion :允许acl命名的IP地址列表内的IP递归查询

  • forwarders: DNS转发器。用于设定该DNS解析服务器无法进行当前域名解析的情况下,进行转发解析的DNS地址,当设置了 forwarder 的转发器之后,所有的非本域的和在缓存中无法查找到的域名查询都转发都设置的DNS转发器,由DNS转发器 完成转发操作。因此这台转发器的缓存中就记录了丰富的域名信息。因此如果遇到非本域的查询,转发器的缓存就可以做到查询,从而减少了向外部的查询流量。

  • allow-transfer: 这个地方的配置是用来给出 Failover 或者是 递归查询DNS服务器的IP地址,如果之前在 options 里配置的allow-transfer 如果设置成了参数 yes, 那么需要在这里指出递归查询服务器的IP地址;

3.修改named.conf.local配置文件

dev@dns_server:/etc/bind$ cat named.conf.local 
//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "test.com" {
	type master;
	file "/etc/bind/db.test.com";
};
zone "0.168.192.in-addr.arpa" {
	type master;
	file "/etc/bind/db.192.168.0";
};

说明:

  • named.conf.local: 用于配置正向和反向代理,此文件用于配置DNS Zone。

  • zone "test.com": 设定了DNS Zone的正向区域,指定DNS所用的域名为test.com

  • zone "0.168.192.in-addr.arpa" : 设定了DNS Zone的反向区域, 指定了IP地址的反写网段

  • file : 指定读取设置正反区域的内容文件

4.设置正向/反向Zone文件【即上一步中file参数的对应文件】

sudo cp /etc/bind/db.local /etc/bind/db.test.com
sudo cp /etc/bind/db.127 /etc/bind/db.192.168.0
  • db.test.com
dev@dns_server:/etc/bind$ cat db.test.com 
;
; BIND data file for local loopback interface
;
$TTL	604800
@	IN	SOA	test.com. root.test.com. (
			      4		; Serial
			 604800		; Refresh
			  86400		; Retry
			2419200		; Expire
			 604800 )	; Negative Cache TTL
;
@	IN	NS	dns.test.com.
test.com.	IN	A	192.168.1.10
dns.test.com.	IN	A	192.168.1.10
host.test.com.	IN	A	192.168.0.10

  • db.192.168.0
dev@dns_server:/etc/bind$ cat db.192.168.0 
;
; BIND reverse data file for local loopback interface
;
$TTL	604800
@	IN	SOA	test.com. root.test.com. (
			      3		; Serial
			 604800		; Refresh
			  86400		; Retry
			2419200		; Expire
			 604800 )	; Negative Cache TTL
;
@	IN	NS	dns.test.com.
10	IN	PTR	test.com.
10	IN	PTR	dns.test.com.
100	IN	PTR	host.test.com.

注意:

1.以上文件内容中,每个域名后边都有一个. 这个.不可省略,不可忽视。

2.在每次修改文件,增加解析的同时也必须修改文件中Serial的值,比当前数字大即可,一般是加1。

5.检查配置文件是否正确

sudo named-checkconf
named-checkzone test.com /etc/bind/db.test.com
named-checkzone 0.168.192.in-addr.arpa /etc/bind/db.192.168.0

# 以上命令如无报错即可重启bind9服务,如有错再次检查以上两个文件是否有误
sudo systemctl restart bind9

6.修改DNS_Sever主机DNS为自建的DNS地址【192.168.1.10】

  • 修改/etc/netplan/目录下的yaml文件
dev@dns_server:/etc/bind$ cat /etc/netplan/00-installer-config.yaml 
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens160:
      addresses:
      - 192.168.1.10/23
      gateway4: 192.168.0.1
      nameservers:
        addresses:
        - 192.168.1.10 # 修改此处,如有多个DNS,需将自建DNS放在第一位
        search: []
  version: 2
  • 改后重启
sudo netplan try
sudo netplan apply
  • 同样的,在window客户端改DNS,也需将自建DNS放在第一位。

三.验证DNS是否生效

  • 在DNS_server上验证
dev@dns_server:/etc/bind$ nslookup dns.test.com
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
Name:	dns.test.com
Address: 192.168.1.10

dev@dns_server:/etc/bind$ ping dns.test.com
PING dns.test.com (192.168.1.10) 56(84) bytes of data.
64 bytes from dns_server (192.168.1.10): icmp_seq=1 ttl=64 time=0.010 ms
64 bytes from dns_server (192.168.1.10): icmp_seq=2 ttl=64 time=0.023 ms
64 bytes from dns_server (192.168.1.10): icmp_seq=3 ttl=64 time=0.023 ms
64 bytes from dns_server (192.168.1.10): icmp_seq=4 ttl=64 time=0.022 ms
^C
--- dns.test.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3067ms
rtt min/avg/max/mdev = 0.010/0.019/0.023/0.007 ms

  • 在Windows客户端上验证
PS C:\Users\ASUS2> ping dns.test.com

正在 Ping dns.test.com [192.168.1.10] 具有 32 字节的数据:
来自 192.168.1.10 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.10 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.10 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.10 的回复: 字节=32 时间<1ms TTL=64

192.168.1.10 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms
PS C:\Users\ASUS2> nslookup dns.test.com
服务器:  UnKnown
Address:  192.168.1.10

名称:    dns.test.com
Address:  192.168.1.10

PS C:\Users\ASUS2> tracert -d dns.test.com

通过最多 30 个跃点跟踪
到 dns.test.com [192.168.1.10] 的路由:

  1    <1 毫秒   <1 毫秒   <1 毫秒 192.168.1.10

跟踪完成。

相关推荐

  1. Ubuntu Server 18.04 DNS服务记录

    2024-04-14 01:10:03       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-14 01:10:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-14 01:10:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-14 01:10:03       82 阅读
  4. Python语言-面向对象

    2024-04-14 01:10:03       91 阅读

热门阅读

  1. iOS cocoapods pod FrozenError and RuntimeError

    2024-04-14 01:10:03       38 阅读
  2. Elasticsearch(ES) 添加/更新映射

    2024-04-14 01:10:03       29 阅读
  3. qt的pushbutton的checked的样式表

    2024-04-14 01:10:03       38 阅读
  4. ER实体关系图

    2024-04-14 01:10:03       34 阅读
  5. webpack里面loader的配置

    2024-04-14 01:10:03       32 阅读
  6. ubuntu安装 Metasploit

    2024-04-14 01:10:03       36 阅读
  7. PG事务、事务隔离级别、并发控制

    2024-04-14 01:10:03       32 阅读
  8. 查询pg 数据库的表行数,和 表大小

    2024-04-14 01:10:03       37 阅读
  9. Git删除未跟踪的文件Untracked files

    2024-04-14 01:10:03       39 阅读
  10. git 拉取项目时切换账号密码

    2024-04-14 01:10:03       34 阅读
  11. select、poll、epoll

    2024-04-14 01:10:03       33 阅读