smartdns 一个强大的dns 服务器

参考架构

 

一个集成其他dns的参考玩法

集成示例

基于docker-compose 运行

  • docker-compose.yaml
version: "3"
services:
  pdnsadmin:
    image: powerdnsadmin/pda-legacy:0.3
    networks:
      dns:
        ipv4_address: 172.16.238.9
    ports:
      - 80:80
    environment:
    - PDNS_API_KEY=a_strong_api_key
    - PDNS_STATS_URL=http://pdns:8081
    - PDNS_API_URL=http://pdns:8081
    - PDNS_VERSION=4.6.2
  pdns:
    image: interlegis/powerdns:4.6.2
    networks:
      dns:
        ipv4_address: 172.16.238.10
    ports:
      -  3053:53
      -  3053:53/udp
      -  8081:8081
    environment:
      - PDNSCONF_API_KEY=a_strong_api_key
      - PDNSCONF_DNSUPDATE=yes
      - SECALLZONES_CRONJOB=yes
      - PDNSCONF_GMYSQL_USER=root
      - PDNSCONF_GMYSQL_DBNAME=powerdns
      - PDNSCONF_GMYSQL_PASSWORD=dalong
  coredns:
    image: dalongrong/coredns
    command: -conf=/opt/Corefile
    networks:
      dns:
        ipv4_address: 172.16.238.11
    volumes:
      - ./Corefile:/opt/Corefile
    ports:
      - 2053:53
      - 2053:53/udp
  mysql:
    image: mysql:8.0.32
    command: --default-authentication-plugin=mysql_native_password --log-bin --binlog-format=ROW --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    networks:
      dns:
        ipv4_address: 172.16.238.12
    environment:
      - MYSQL_ROOT_PASSWORD=dalong
      - MYSQL_DATABASE=powerdns
    ports:
      - 3306:3306
  app:
     image: pymumu/smartdns:latest
     networks:
      dns:
        ipv4_address: 172.16.238.13
     volumes:
       - ./smartdns:/etc/smartdns
     ports:
       - 1053:53/udp
       - 1053:53/tcp
networks:
  dns:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
  • coredns 配置
.:53 {
   mysql {
    dsn root:dalong@tcp(mysql:3306)/powerdns?tls=skip-verify&autocommit=true
    ttl 20
  }
}
  • smartdns 配置
    此服务包含了转发coredns 以及powerdns 的配置
 
bind [::]:53
server 8.8.8.8
server 1.222.1.1
server 172.16.238.11
server 172.16.238.10
server 114.114.114.114
audit-enable yes
cache-size 32768
rr-ttl 5
cache-persist yes
prefetch-domain yes
log-level   debug
log-console  yes
cache-file /var/cache/file
serve-expired-prefetch-time 0
address /example.com/1.2.3.4
address /example.com/4.5.6.7,8.9.10.11,12.13.14.15,113.156.178.1
cname /dalong.com/example.com
ip-alias 1.2.3.4/32 192.168.1.1
  • 启动
docker-compose up -d 

注意启动之后需要创建coredns 的记录表,powerdns 就不需要

CREATE TABLE `coredns_records` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `zone` VARCHAR(255) NOT NULL,
    `name` VARCHAR(255) NOT NULL,
    `ttl` INT DEFAULT NULL,
    `content` TEXT,
    `record_type` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = INNODB AUTO_INCREMENT = 6 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;

配置powerdns admin 以及添加coredns 记录

 


添加记录

 


coredns 记录

 
INSERT INTO coredns_records (zone, name, ttl, content, record_type) VALUES
('appdemo.org.', 'foo', 30, '{"ip": "1.1.1.1"}', 'A')
  • 查询效果

 

说明

基于smartdns 提供的一些能力以及利用一些开源dns server 可以实现比较灵活的dns 控制,完整的示例我已经push 到github 了,可以参考

参考资料

https://github.com/pymumu/smartdns
https://github.com/PowerDNS/pdns
https://github.com/PowerDNS-Admin/PowerDNS-Admin
https://pymumu.github.io/smartdns/configuration/
https://coredns.io/
https://github.com/rongfengliang/smartdns_coredns_powerdns_learning

posted on 2023-11-02 10:25  荣锋亮  阅读(1791)  评论(0编辑  收藏  举报

导航