参考来源:
Debian 环境下简单配置 Bind9 服务 --2018年腾讯云社区的作者:Debian中国
https://wiki.debian.org/Bind9#Definitions --官网wiki
Debian10搭建bind9主服务器搭建 --站内文档
域名解析的过程:pass
域名相关的服务器的类别和作用:pass
域名服务器高可用主从方式的实现:pass
bind应用的实现过程:
安装软件,服务状态检查–包管理器apt-get方式安装,;
apt-get install bind9
apt-get install bind9-host dnsutils
apt-get install bind9-doc
root@debian:/etc/bind# systemctl status bind9
● named.service - BIND Domain Name Server
Loaded: loaded (/lib/systemd/system/named.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-08-13 23:56:31 CST; 48min ago
Docs: man:named(8)
Main PID: 30911 (named)
Tasks: 6 (limit: 4645)
Memory: 18.0M
CPU: 1.385s
CGroup: /system.slice/named.service
└─30911 /usr/sbin/named -f -u bind
...
配置文件的路径和修改;
配置文件在/etc/bind/目录下,主配置文件为named.conf
root@debian:/etc/bind# ls -l
总用量 60
-rw-r--r-- 1 root root 1991 7月 23 21:15 bind.keys
-rw-r--r-- 1 root root 237 7月 23 21:15 db.0
-rw-r--r-- 1 root root 309 8月 13 23:32 db.111.com
-rw-r--r-- 1 root root 271 7月 23 21:15 db.127
-rw-r--r-- 1 root root 273 8月 13 23:34 db.192.168
-rw-r--r-- 1 root root 237 7月 23 21:15 db.255
-rw-r--r-- 1 root root 353 7月 23 21:15 db.empty
-rw-r--r-- 1 root root 270 7月 23 21:15 db.local
-rw-r--r-- 1 root bind 463 7月 23 21:15 named.conf
-rw-r--r-- 1 root bind 498 7月 23 21:15 named.conf.default-zones
-rw-r--r-- 1 root bind 317 8月 13 23:43 named.conf.local
-rw-r--r-- 1 a a 941 8月 13 22:01 named.conf.log
-rw-r--r-- 1 root bind 868 8月 13 23:56 named.conf.options
-rw-r----- 1 bind bind 100 8月 13 20:29 rndc.key
-rw-r--r-- 1 root root 1317 7月 23 21:15 zones.rfc1918
查看配置文件named.conf内容,得到两个关键信息:
1.区域配置文件的信息,有三个named.conf.{options,local,default-zones}
2.帮助文档的路径/usr/share/doc/bind9/README.Debian.gz
root@debian:/etc/bind# cat named.conf
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local
include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";
场景化的需求实现-企业内部搭建dns服务器项目
通过查看配置文件内容和Dibian的wiki参考资料,进行企业内部搭建dns服务的场景化需求实现,之前上学时候的实训课程项目中,做过几乎一样的实验,但当时是在red hat操作系统上实现的;
场景关键信息提取:
1.有一个内部web网站,地址:192.168.255.129/24,对应虚拟主机服务配置为www.111.com;
2.有一个待实现的内部DNS服务器,通过配置正反向解析记录配置,内部设备通过配置dns服务器地址,实现对于www.111.com域名的解析,访问web网站上的服务;
场景实现:
服务端配置
修改/etc/bind/named.conf.local配置文件,配置正反向解析记录,正向是从域名到主机,反向是从主机到域名;
添加111.com和168.192.in-addr.arpa的解析记录;
root@debian:/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 "111.com" {
type master;
file "/etc/bind/db.111.com";
};
zone "168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168";
};
参考原有配置文件中的db.local和db.127文件,配置web网站虚拟主机www.111.com和ip:192.168.255.129的映射关系,对于SOA/NS/A/PTR等关键字的解读,可以参考官方wiki的注释,https://wiki.debian.org/Bind9#Definitions
root@debian:/etc/bind# cat db.local
;
; 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
root@debian:/etc/bind# cat db.111.com
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA 111.com. admin.111.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.111.com.
@ IN A 192.168.255.130
ns IN A 192.168.255.130
www IN A 192.168.255.129
root@debian:/etc/bind# cat db.127
;
; 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 localhost.
1.0.0 IN PTR localhost.
root@debian:/etc/bind# cat db.192.168
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA 111.com. admin.111.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.111.com.
255.129 IN PTR www.111.com.
root@debian:/etc/bind#
到这里,dns解析配置操作基本完成,修改了named.conf.local配置文件,创建了两个解析空间的文件;重启服务使配置生效;
官方文档中还有通过命令进行配置文件语法检查的信息,可参考,示例如下:
root@debian:/etc/bind# named-checkzone 111.com /etc/bind/db.111.com
zone 111.com/IN: loaded serial 2
OK
root@debian:/etc/bind# named-checkzone 192.168.255.129 /etc/bind/db.192.168
zone 192.168.255.129/IN: loaded serial 1
OK
root@debian:/etc/bind# systemctl restart bind9
接下来是客户端dns的配置和域名相关测试,域名测试部分,官方wiki上同样有dig/nslookup工具使用,正反向解析的示例;
客户端配置
首先在web服务设备(192.168.255.129)上通过curl访问web服务,禁用本地hosts文件中的解析记录,在resolv.conf配置dns服务器地址192.168.255.130
[root@centos7 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#192.168.255.129 www.111.com
192.168.255.129 www.aaa.com
192.168.255.129 www.bbb.com
192.168.255.129 www.smile.com www.long.com
[root@centos7 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.255.130
#nameserver 127.0.0.1
[root@centos7 ~]#
测试,查看指标,验证效果
dig工具的正反向域名查询验证,关注ANSWER SECTION和SERVER两个字段的值;
[root@centos7 ~]# dig www.111.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.15 <<>> www.111.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57220
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.111.com. IN A
;; ANSWER SECTION:
www.111.com. 604800 IN A 192.168.255.129
;; Query time: 0 msec
;; SERVER: 192.168.255.130#53(192.168.255.130)
;; WHEN: 二 8月 13 23:50:05 CST 2024
;; MSG SIZE rcvd: 56
[root@centos7 ~]# dig -x 192.168.255.129
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.15 <<>> -x 192.168.255.129
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 7963
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;129.255.168.192.in-addr.arpa. IN PTR
;; AUTHORITY SECTION:
168.192.in-addr.arpa. 604800 IN SOA 111.com. admin.111.com. 1 604800 86400 2419200 604800
;; Query time: 0 msec
;; SERVER: 192.168.255.130#53(192.168.255.130)
;; WHEN: 三 8月 14 01:29:29 CST 2024
;; MSG SIZE rcvd: 126
[root@centos7 ~]#
nslookup工具的验证
root@debian:/etc/bind# nslookup www
Server: 192.168.255.130
Address: 192.168.255.130#53
Name: www.111.com
Address: 192.168.255.129
curl工具模拟浏览器访问网站,用户侧验证效果,已实现预期效果
[root@centos7 ~]# curl www.111.com
xiaoyue,hello this is www.111.com
[root@centos7 ~]# ip a | grep 129
inet 192.168.255.129/24 brd 192.168.255.255 scope global noprefixroute dynamic ens33
root@debian:/etc/bind# curl www.111.com
xiaoyue,hello this is www.111.com
root@debian:/etc/bind# ip a | grep 130
inet 192.168.255.130/24 brd 192.168.255.255 scope global dynamic noprefixroute ens33
–END提示–