系统环境

标题 版本 备注
系统版本 ubuntu 22.04.3 LTS (Jammy Jellyfish) -
内核版本 5.15.0-88-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux -
Bind v9.18.12 -

Bind 简介

BIND(Berkeley Internet Name Domain)是一个开源的域名系统(DNS)软件套件,广泛用于互联网上的域名解析服务。BIND包含了一系列的DNS服务器软件,它允许计算机网络上的计算机将其域名转换为 IP 地址。

以下是BIND的一些关键特性和优势:

  1. 可扩展性:BIND支持多种DNS协议,包括DNSSEC(DNS安全扩展)等,并且具有灵活的插件系统,使得其在不同的环境和场景中都能够满足需求。

  2. 高性能:BIND具有出色的性能和稳定性,可以处理大量的DNS查询请求,并且支持多线程和异步操作,提高了系统的吞吐量和响应速度。

  3. 安全性:BIND具有丰富的安全功能,包括访问控制、数据加密、防止DNS缓存投毒等,保障了DNS服务的安全性和可靠性。

  4. 灵活的配置:BIND采用文本配置文件来进行配置,配置文件结构清晰,易于理解和维护,并且支持动态更新配置,提高了系统的灵活性和可管理性。

  5. 广泛的应用:BIND被广泛应用于互联网上的DNS服务器、域名注册商和企业网络中的DNS服务器等场景,是目前最流行的DNS软件之一。

总的来说,BIND是一种功能强大、性能优越、安全可靠的域名系统软件套件,为互联网上的域名解析服务提供了重要支持。

Bind 部署

安装 bind9 及主配置文件修改

1.执行安装命令

sudo apt install bind9 bind9utils bind9-doc bind9-dnsutils

2.修改配置文件 /etc/bind/named.conf.options, 如下:

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.korg/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.

// DNS 转发器,用于设定该 DNS 解析服务器无法进行当前域名解析的情况下,进行转发解析的 DNS 地址
forwarders {
114.114.114.114;
8.8.8.8;
};

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

// listen-on-v6 { any; };
};

3.修改 /etc/default/named 文件,在 OPTIONS 后面添加 -4 参数,如下:

#
# run resolvconf?
RESOLVCONF=no

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

添加域名解析

1.修改配置文件 /etc/bind/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 "customer.com" {
type master;
file "/etc/bind/zones/db.customer.com";
};

// 反向解析
zone "168.192.in-addr.arpa" {
type master;
file "/etc/bind/zones/db.168.192";
};

2.在 /etc/bind/ 目录下创建域名解析文件存放目录 zones:

sudo mkdir /etc/bind/zones

3.在 /etc/bind/zones 目录下创建 db.customer.comdb.168.192 文件,内容分别为:

3.1.正向解析文件:db.customer.com 配置内容如下:

;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA customer.com. root.customer.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
@ IN A 127.0.0.1
;@ IN AAAA ::1
dhcp IN A 102.168.1.201
ntp IN A 192.168.1.203
ftp IN A 192.168.1.204
dns IN A 192.168.1.202

3.2.反向解析文件:db.168.192 配置内容如下:

;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA customer.com. root.customer.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
1.0.0 IN PTR localhost.
201.1 IN PTR dhcp
203.1 IN PTR ntp
204.1 IN PTR ftp
202.1 IN PTR dns

检查配置及启动服务

1.执行命令,检查正向解析和反向解析 配置文件是否正确:

# 主配置文件检查
leazhi@ubuntu2204-001:~$ sudo named-checkconf /etc/bind/named.conf

# 正向解析文件配置检查
leazhi@ubuntu2204-001:~$ sudo named-checkzone customer.com /etc/bind/zones/db.customer.com
zone customer.com/IN: loaded serial 2
OK

# 反向解析文件配置检查
leazhi@ubuntu2204-001:~$ sudo named-checkzone 168.192.in-addr.arpa /etc/bind/zones/db.customer.com
zone 168.192.in-addr.arpa/IN: loaded serial 2
OK

2.启动bind服务:

sudo systemctl enable --now named.service

3.检查bind服务是否启动:

leazhi@ubuntu2204-001:~$ sudo systemctl status named.service
● named.service - BIND Domain Name Server
Loaded: loaded (/lib/systemd/system/named.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2023-09-03 02:12:12 UTC; 37min ago
Docs: man:named(8)
Process: 15851 ExecStart=/usr/sbin/named $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 15852 (named)
Tasks: 4 (limit: 935)
Memory: 4.3M
CPU: 188ms
CGroup: /system.slice/named.service
└─15852 /usr/sbin/named -u bind -4

解析测试

1.编辑本地的 /etc/resolv.conf 文件,添加如下内容:

nameserver 127.0.0.1

2.测试解析:

2.1.nslookup 命令测试:

# 正向解析测试:
leazhi@ubuntu2204-001:~$ nslookup ftp.customer.com
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: ftp.customer.com
Address: 192.168.1.204


# 反向解析测试:
leazhi@ubuntu2204-001:~$ nslookup 192.168.1.204
204.1.168.192.in-addr.arpa name = ftp.168.192.in-addr.arpa.

2.2.dig 命令测试:

# 正向解析测试:
leazhi@ubuntu2204-001:~$ dig ntp.customer.com

; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> ntp.customer.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29507
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 96fcfa9c323165c90100000064f3fc2ffa9a4d1f0d01e293 (good)
;; QUESTION SECTION:
;ntp.customer.com. IN A

;; ANSWER SECTION:
ntp.customer.com. 604800 IN A 192.168.1.203

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1) (UDP)
;; WHEN: Sun Sep 03 03:23:27 UTC 2023
;; MSG SIZE rcvd: 89


# 反向解析测试:
leazhi@ubuntu2204-001:~$ dig -x 192.168.1.203

; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> -x 192.168.1.203
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17870
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 2e3d235566ef03400100000064f3fc374bbe3a1eac2f0324 (good)
;; QUESTION SECTION:
;203.1.168.192.in-addr.arpa. IN PTR

;; ANSWER SECTION:
203.1.168.192.in-addr.arpa. 604800 IN PTR ntp.168.192.in-addr.arpa.

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1) (UDP)
;; WHEN: Sun Sep 03 03:23:35 UTC 2023
;; MSG SIZE rcvd: 121