使用PowerDNS实现内网DNS解析

部署环境

公司内部安装powerdns实现局域网服务dns解析,避免通过ip访问。

系统: CentOS 7.9
mysql版本: 5.7.33
pdns版本: 4.4.1
pdns-recursor版本: 4.4.2
PowerDNS-admin版本: 0.2.3
DNS服务器主机: 10.x.x.109
测试服务器ip: 10.y.y.195

  1. 使用docker方式安装mysql,docker-compose.yml如下所示:
---
version: '3.7'

services:
  mysql:
    hostname: mysql
    container_name: mysql
    restart: always
    image: mysql:5.7.33
    ports:
      - 3306:3306
    command: [
      '--default-authentication-plugin=mysql_native_password',
      '--max_connections=5000',
      '--expire_logs_days=5',
      '--character-set-server=utf8mb4',
      '--collation-server=utf8mb4_unicode_ci',
      '--slow_query_log=on',
      '--long_query_time=2',
      '--slow_query_log_file=/var/lib/mysql/slow_query.log'
    ]
    environment:
      MYSQL_DATABASE: powerdns
      MYSQL_ROOT_PASSWORD: XpWxxxxx0WmE
      MYSQL_USER: normal
      MYSQL_PASSWORD: 2GVoxxxxxtUsI5y
    volumes:
      - /data/mysql/data:/var/lib/mysql
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
      - ./my.cnf:/etc/mysql/my.cnf
    networks:
      - mysql

networks:
  mysql:
    external: true

mysql配置my.cnf如下:

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

slow_query_log = on
long_query_time = 2
slow_query_log_file = /var/lib/mysql/slow_query.log
log_queries_not_using_indexes = ON

max_connections = 4000

skip-name-resolve
#lower_case_table_names = 1

# Custom config should go here
!includedir /etc/mysql/conf.d/
  1. 配置powerdns yum源
yum install epel-release yum-plugin-priorities &&
curl -o /etc/yum.repos.d/powerdns-auth-44.repo https://repo.powerdns.com/repo-files/centos-auth-44.repo && yum makecache fast
  1. 安装pdns及pdns连接mysql插件
yum install pdns.x86_64 pdns-backend-mysql.x86_64

修改pdns.conf配置:

api=yes
api-key=Qno9k64Vkkkyfz1LtC3klk
daemon=no
guardian=no
launch=gmysql
gmysql-host=10.x.x.109
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=root
gmysql-password=XpWxxxxx0WmE
local-address=0.0.0.0, ::
local-port=5300
setgid=pdns
setuid=pdns
webserver=yes
webserver-address=0.0.0.0
webserver-allow-from=0.0.0.0/0
webserver-port=8081

初始化数据库:

mysql -h10.x.x.109 -uroot -pXpWxxxxx0WmE -e "use powerdns; source /usr/share/doc/pdns-backend-mysql-4.4.1/schema.mysql.sql;"

启动pdns服务:

systemctl start pdns && systemctl enable pdns
  1. 安装递归查询服务pdns-recursor
  • 配置yum源
curl -o /etc/yum.repos.d/powerdns-rec-44.repo https://repo.powerdns.com/repo-files/centos-rec-44.repo && yum makecache fast
  • 安装pdns-recursor
yum install pdns-recursor
  • 修改pdns-recursor配置文件pdns-recursor.conf
allow-from=10.10.0.0/16, 10.20.0.0/16      #对应权威服务器的allow-recursion 允许哪些ip进行递归
#forward-zones=mydomain.com=10.x.x.109:5300      #哪些域名需要自己的权威服务器来解析,域名=权威服务器ip:端口
forward-zones-file=/etc/pdns-recursor/zones
forward-zones-recurse=.=223.5.5.5, .=180.76.76.76, .=114.114.114.114           # 除forward-zones外其他所有的请求发至223.5.5.5, 180.76.76.76, 114.114.114.114
local-address=0.0.0.0         #对应权威服务器的local-address
local-port=53
setgid=pdns-recursor
setuid=pdns-recursor
  • 配置哪些域名强制走内网dns解析,/etc/pdns-recursor/zones配置如下
+mydomain.com=10.x.x.109:5300
test.dev.mydomain.com=10.x.x.109:5300
test2.prod.mydomain.com=10.x.x.109:5300
  • 启动pdns-recursor服务
systemctl start pdns-recursor && systemctl enable pdns-recursor
  1. 安装PowerDNS管理后台服务powerdns-admin,docker-compose.ymk如下
---
version: '3.7'

services:
  powerdnsadmin:
    hostname: pdnsadmin
    container_name: pdnsadmin
    image: ngoduykhanh/powerdns-admin:0.2.3
    restart: always
    ports:
      - 80:80
    networks:
      - pdns
    volumes:
      - /data/pdnsadmin/data:/data
    logging:
      driver: json-file
      options:
        max-file: '3'
        max-size: '10m'

networks:
  pdns:
    driver: bridge
    external: true
  1. 访问powerdns-admin页面并配置接口信息
    在这里插入图片描述
  • 添加A记录
    在这里插入图片描述
  1. 修改测试客户端10.y.y.195的dns ip为10.x.x.109并解析上一步添加的A记录
    在这里插入图片描述
  • 解析A记录
    在这里插入图片描述
  • 解析baidu.com,通过内网递归查询到外部域名
    在这里插入图片描述

至此内网单机版dns服务器部署完毕,可以正常解析域名。

备注:
高可用dns服务可通过后端mysql实现主从实现,配置两个pdns。

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值