PowerDNS-Recursor递归服务器部署及调试

最后更新于 14 天前 23 次阅读


由于博主所在公司的工厂需要部署一台DNS递归服务器用于向总部的DNS服务器解析域名信息,所以博主在自己的fedora虚拟机上先尝试部署了一下,特在此记录一下部署过程。

一、应用场景

递归服务器权威服务器的区别在于,递归服务器本身并不提供解析,而是将客户端需要解析的内容交由其它服务器来进行解析,而权威服务器则是直接查询数据库去尝试解析,数据库中若不存在此记录,则直接返回空结果。为了更简单理解,不妨举个例子:用户要通过权威服务器来解析big.wind域名,权威服务器的做法是,查询本地数据库,有则返回结果,木有则返回空,当然对于用户来说,返回空则代表解析失败;用户通过递归服务器来解析big.wind域名,递归服务器此时可以设置成两种方式:

方式一:把解析请求转给权威服务器,权威服务器上若存在该记录,则返回该记录的解析结果,若不存在该记录,则返回空,用户解析失败;

方式二:把继续请求转给权威服务器,权威服务器上若存在该记录,则返回该记录的解析结果,若不存在该记录,则继续通过递归方式向其它DNS查询该记录,最终,若查询到,则返回结果,若查询不到,则返回空,用户解析失败。

二、部署环境

系统:Fedora 42

pdns-recursor版本:5.2

三、部署命令

fedora

dnf install -y pdns-recursor 

`等待安装完成即可。

四、进行基础配置

配置文档可以参考:https://doc.powerdns.com/recursor/yamlsettings.html

5.0版本后的recursor,在pdns-recursor的文件夹下如果同时存在recursor.conf和recursor.yml两个文件时,将优先使用recursor.yml文件

修改配置文件/etc/pdns-recursor/recursor.yml-list,修改后文件如下:

fedora 5.2版本的recursor.yml-list配置文件

#注意yaml要严格控制缩进,每一层级用空格做两次缩进,禁止使用Tab键。

记得在修改文件前,先把yaml文件备份:cp /etc/pdns-recursor/recursor.yml-list /etc/pdns-recursor/recursor.yml-list.bak

recursor:
  setgid: 'pdns-recursor'
  setuid: 'pdns-recursor'

# 接受哪些IP的查询请求,0.0.0.0/0表示全部
# 本地监听的接口IP地址
incoming:
  allow_from:
    - 0.0.0.0/0
    - ::/0
  listen:
    - 0.0.0.0
# 关闭dnssec功能,4.5版本后默认开启
dnssec:
  validation: off

#验证yaml文件语法的代码:

pdns_recursor --config --config-dir=/etc/pdns-recursor

五、启动并查看配置

systemctl enable pdns-recursor --now

systemctl status pdns-recursor 

六、进行dns转发配置

递归服务器(pdns-recursor)日常操作相对权威服务器而言要少很多,递归服务器并没有图形化配置界面,也没必要,主要操作即修改递归服务器的配置文件/etc/pdns-recursor/recursor.yml-list来实现。

vi /etc/pdns-recursor/recursor.yml-list

# 转发请求,不允许递归。
forward_zones:
  - zone: big.wind
    servers:
      - 10.210.11.5
  - zone: a.b.c
    servers:
      - 10.5.2.4:553
# **转发请求,并允许递归,以这个配置为主**。
  forward_zones_recurse:
    - zone: baidu.com
      servers:
        - 223.5.5.5
    - zone: .
      servers:
        - 119.29.29.29

该配置命令实际效果:

(1)、用户请求递归服务器解析*.big.wind,递归服务器会向10.210.11.5来询问结果,若10.210.11.5存在这条记录,则将解析结果返回给递归服务器,递归服务器再返回给用户,用户得到解析结果,若10.210.11.5不存在这条记录,则返回空值给递归服务器,递归服务器将此空值返回给用户,用户则解析该域名失败,同理,a.b.c将向10.5.2.4的553端口来进行询问,并以同样的方式来工作。

(2)、用户请求递归服务器解析map.baidu.com,递归服务器会向223.5.5.5来询问结果,当然,因为223.5.5.5并非是baidu.com的权威服务器,所以不会存在map.baidu.com的记录,但纵然是没有, 223.5.5.5也能通过其它方式获取到baidu.com的解析结果,并将结果返回给递归服务器,递归服务器拿到这个结果后,返回给用户。同样,其它域名会向119.29.29.29来询问。

保存后重启pdns-recursor再进行测试:

#先把本机的dns切换为127.0.0.1
vi /etc/resolv.conf
nameserver 127.0.0.1

#然后开启一个新的终端进行抓包
tcpdump -i any host 223.5.5.5 and port 53 -n
tcpdump -i any host 119.29.29.29 and port 53 -n

#然后分别进行测试,先测试223.5.5.5这个地址有没有报文
dig www.baidu.com 
测试结果:
[root@fedora log]# sudo tcpdump -i any host 223.5.5.5 and port 53 -n
tcpdump: WARNING: any: That device doesn't support promiscuous mode
(Promiscuous mode not supported on the "any" device)
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
^C
0 packets captured
**2 packets received by filter #证明有报文通过**
0 packets dropped by kernel

#再测试下119.29.29.29
dig www.sina.com
dig www.360.com

七、调试WebUI界面和Api设置

pdns-recursor提供了一个WebUI界面用于用户查看服务器状态,我们需要在recursor.confrecursor.yml-list这两个配置文件中同时配置并开启该webUI服务

**#recursor.conf**
vi /etc/pdns-recursor/**recursor.conf**

######### SECTION webservice #########
webservice:
##### IP Address of webserver to listen on
  address: 0.0.0.0
##### Webserver access is only allowed from these subnets
  allow_from:
    - 0.0.0.0/0
    - ::1
##### Directory where REST API stores config and zones
#   api_dir: ''
##### Static pre-shared authentication key for access to the REST API
  api_key: 'zhaodsmm123'
##### Whether to hash passwords and api keys supplied in plaintext, to prevent keeping the plaintext version in memory at runtime
  hash_plaintext_credentials: true
##### Amount of logging in the webserver (none, normal, detailed)
  loglevel: detailed
##### Password required for accessing the webserver
#  password: 'zhaodsmm123'
##### Port of webserver to listen on
  port: 8082
##### Start a webserver (for REST API)
  webserver: true

**#recursor.yml-list**
vi /etc/pdns-recursor/**recursor.yml-list**

######### SECTION webservice #########
webservice:
##### IP Address of webserver to listen on
  address: 0.0.0.0
##### Webserver access is only allowed from these subnets
  allow_from: ["0.0.0.0/0", "::1"]
##### Directory where REST API stores config and zones
#   api_dir: ''
##### Static pre-shared authentication key for access to the REST API
  api_key: 'zhaodsmm123'
##### Whether to hash passwords and api keys supplied in plaintext, to prevent keeping the plaintext version in memory at runtime
#   hash_plaintext_credentials: false
##### Amount of logging in the webserver (none, normal, detailed)
  loglevel: normal
##### Password required for accessing the webserver
#  password: 'zhaodsmm123'
##### Port of webserver to listen on
  port: 8082
##### Start a webserver (for REST API)
  webserver: true

#保存后,重启pdns-recursor服务,并查看8082端口是否正常在监听
systemctl restart pdns-recursor
lsof -i:8082

[root@fedora pdns-recursor]# lsof -i:8082
COMMAND       PID          USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
pdns_recu 3667167 pdns-recursor   39u  IPv4 8986535      0t0  TCP *:us-cli (LISTEN)

配置完成后登录http://ip:8082即可访问。

剩下的配置后续在补充吧......