内网部署 DNS 服务器(Technitium)

26 人赞同了该文章
目录
收起
Technitium
Doc
Prerequisite
Install
Set up
web ui
Recursion
Proxy & Forwarders
Add Zone
import Zone file
generate Zone file
import zone file

Technitium

之前写过一篇使用 ADguardHome 搭建 DNS 服务器的博客.

AD 的功能还是太简单了,不适合更复杂的场景.

介绍一下 Technitium 搭建 DNS 服务器.

Doc

https://hub.docker.com/r/technitium/dns-server
https://technitium.com/dns/
https://github.com/TechnitiumSoftware/DnsServer

Prerequisite

  • linux 主机,1c1g
  • 安装 docker
  • 不要在公网环境搭建,会被ban.

Install

  • 创建文件 docker-compse.yml
  • 5380 端口是 web 界面,53 端口是标准的 DNS 服务器端口
  • 如果有其他需求,DOH,DOT,DOQ ,按需开启其他端口
  • volumes 没有填具体的文件目录路径,如果你有数据持久化的需要,可以填一个
services:
  dns-server:
    container_name: dns-server
    hostname: dns-server
    image: technitium/dns-server:latest
    # For DHCP deployments, use "host" network mode and remove all the port mappings, including the ports array by commenting them
    # network_mode: "host"
    ports:
      - "5380:5380/tcp" #DNS web console (HTTP)
      # - "53443:53443/tcp" #DNS web console (HTTPS)
      - "53:53/udp" #DNS service
      - "53:53/tcp" #DNS service
      # - "853:853/udp" #DNS-over-QUIC service
      # - "853:853/tcp" #DNS-over-TLS service
      # - "443:443/udp" #DNS-over-HTTPS service (HTTP/3)
      # - "443:443/tcp" #DNS-over-HTTPS service (HTTP/1.1, HTTP/2)
      # - "80:80/tcp" #DNS-over-HTTP service (use with reverse proxy or certbot certificate renewal)
      # - "8053:8053/tcp" #DNS-over-HTTP service (use with reverse proxy)
      # - "67:67/udp" #DHCP service
    environment:
      - DNS_SERVER_DOMAIN=dns-server #The primary domain name used by this DNS Server to identify itself.
      # - DNS_SERVER_ADMIN_PASSWORD=password #DNS web console admin user password.
      # - DNS_SERVER_ADMIN_PASSWORD_FILE=password.txt #The path to a file that contains a plain text password for the DNS web console admin user.
      # - DNS_SERVER_PREFER_IPV6=false #DNS Server will use IPv6 for querying whenever possible with this option enabled.
      # - DNS_SERVER_WEB_SERVICE_LOCAL_ADDRESSES=172.17.0.1,127.0.0.1 #Comma separated list of network interface IP addresses that you want the web service to listen on for requests. The "172.17.0.1" address is the built-in Docker bridge. The "[::]" is the default value if not specified. Note! This must be used only with "host" network mode.
      # - DNS_SERVER_WEB_SERVICE_HTTP_PORT=5380 #The TCP port number for the DNS web console over HTTP protocol.
      # - DNS_SERVER_WEB_SERVICE_HTTPS_PORT=53443 #The TCP port number for the DNS web console over HTTPS protocol.
      # - DNS_SERVER_WEB_SERVICE_ENABLE_HTTPS=false #Enables HTTPS for the DNS web console.
      # - DNS_SERVER_WEB_SERVICE_USE_SELF_SIGNED_CERT=false #Enables self signed TLS certificate for the DNS web console.
      # - DNS_SERVER_OPTIONAL_PROTOCOL_DNS_OVER_HTTP=false #Enables DNS server optional protocol DNS-over-HTTP on TCP port 8053 to be used with a TLS terminating reverse proxy like nginx.
      # - DNS_SERVER_RECURSION=AllowOnlyForPrivateNetworks #Recursion options: Allow, Deny, AllowOnlyForPrivateNetworks, UseSpecifiedNetworkACL.
      # - DNS_SERVER_RECURSION_NETWORK_ACL=192.168.10.0/24, !192.168.10.2 #Comma separated list of IP addresses or network addresses to allow access. Add ! character at the start to deny access, e.g. !192.168.10.0/24 will deny entire subnet. The ACL is processed in the same order its listed. If no networks match, the default policy is to deny all except loopback. Valid only for `UseSpecifiedNetworkACL` recursion option.
      # - DNS_SERVER_RECURSION_DENIED_NETWORKS=1.1.1.0/24 #Comma separated list of IP addresses or network addresses to deny recursion. Valid only for `UseSpecifiedNetworkACL` recursion option. This option is obsolete and DNS_SERVER_RECURSION_NETWORK_ACL should be used instead.
      # - DNS_SERVER_RECURSION_ALLOWED_NETWORKS=127.0.0.1, 192.168.1.0/24 #Comma separated list of IP addresses or network addresses to allow recursion. Valid only for `UseSpecifiedNetworkACL` recursion option.  This option is obsolete and DNS_SERVER_RECURSION_NETWORK_ACL should be used instead.
      # - DNS_SERVER_ENABLE_BLOCKING=false #Sets the DNS server to block domain names using Blocked Zone and Block List Zone.
      # - DNS_SERVER_ALLOW_TXT_BLOCKING_REPORT=false #Specifies if the DNS Server should respond with TXT records containing a blocked domain report for TXT type requests.
      # - DNS_SERVER_BLOCK_LIST_URLS= #A comma separated list of block list URLs.
      # - DNS_SERVER_FORWARDERS=1.1.1.1, 8.8.8.8 #Comma separated list of forwarder addresses.
      # - DNS_SERVER_FORWARDER_PROTOCOL=Tcp #Forwarder protocol options: Udp, Tcp, Tls, Https, HttpsJson.
      # - DNS_SERVER_LOG_USING_LOCAL_TIME=true #Enable this option to use local time instead of UTC for logging.
    volumes:
      - config:/etc/dns
    restart: unless-stopped
    sysctls:
      - net.ipv4.ip_local_port_range=1024 65000

volumes:
    config:

cmd

# start
docker compose up -d
# stop
docker compose down

假设,你的服务器 ip 为 192.168.4.145

访问以下地址进入 web 管理界面.

http://192.168.4.145:5380

第一次登录,会让你设置用户密码.

Set up

web ui

你只需要关注两个地方 zone 和 Setting.

  • zone 设置域名的 zone 文件
  • setting 是关于服务器的设置


在 Setting 里面关注两个地方

  • Recursion 关于服务器递归查询的设置
  • Forwarders 上游 DNS 服务器设置


Recursion

改成第二个 Allow Recursion ,允许递归,接收任何地方的请求.

Proxy & Forwarders

  • Quick Select 那里快速选择上游的 DNS 服务器(选一个你能连接的)
  • Forwarder Protocol 选择你用什么协议转发请求

这一页的最下方,给出两个官方文档链接

Add Zone

我们点击右上角 Add Zone 开始添加第一个 Zone.

Zone 我们不去介绍,这是 DNS 服务器基本知识.

我们添加的第一个 zone 是关于域名 hellodns.intranet 的.

关于类型的介绍

编号类型描述用途适用场景
1Primary Zone这是默认选项,用于配置该服务器作为主 DNS 服务器。自定义并维护整个 DNS 区域数据,提供权威 DNS 响应。新建一个 DNS 区域,所有记录都在此服务器上编辑和管理。
2Secondary Zone这类区域会从另一个主 DNS 服务器中复制数据(也称为从属 DNS 服务器)。用于高可用和负载均衡,定期从 Primary Zone 同步数据。做为主 DNS 服务器的冗余备份或从主服务器复制记录。
3Stub Zone仅存储其他 DNS 区域的 NS 记录和相关 Glue Record(名称服务器的 IP)。用于快速查找特定区域的权威服务器,而不用存储整个区域的数据。大型环境中优化递归查询路径。
4Conditional Forwarder Zone将某些特定域名的 DNS 查询转发到指定的 DNS 服务器。定制 DNS 解析路径,用于处理跨组织或跨网络的域名。跨域环境中的专用解析。
5Secondary Conditional Forwarder Zone类似 Conditional Forwarder,但以 Secondary 方式存在,会从另一个 DNS 服务器中同步。在特定域的条件转发基础上添加冗余同步机制。较大的环境中需要转发并保持高可用性。
6Catalog Zone用于动态管理和分发一组 DNS 区域的元信息。自动化管理多个区域的 DNS 数据。需要管理多个子域或大量子域环境的自动化。
7Secondary Catalog ZoneCatalog Zone 的从属版本,用于同步并缓存元信息。从另一个 DNS 服务器复制 Catalog Zone 的数据。大规模分布式环境中动态更新 Catalog。
8Secondary ROOT Zone (RFC 8806)配置该服务器同步和缓存根区域的数据。提高递归 DNS 查询速度,避免直接查询根服务器。大型 DNS 服务商或有高性能需求的网络环境。

点击 Add Record 可以添加对域名和二级域名的 DNS 记录.

我们添加的 DNS 记录有以下两个.

TTL 统一设置为 60.

hellodns.intranet - 192.168.145.10
api.hellodns.intranet - 192.192.145.11

import Zone file

generate Zone file

使用 zone 文件管理,是更专业的做法.

在这里,我们不用手写 zone 文件. (太麻烦了)

我们使用 zone 文件生成器.

谷歌bind9 zone file generator

我们用搜索出来的第一个结果,来生成 zone 文件.

https://nimmneun.com/toolbox/bind-zone-file-generator/

我们为 hellozone.intranet 生成 zone 文件

生成出来的部分文件内容.

$TTL    7200
api IN  A   192.168.145.13 
log IN  A 192.168.145.14

import zone file

选择导入 zone

复制粘贴,不要勾选,下面的 Overwrite .

因为我们只是用了一部分 zone 文件

返回界面,你就会看到添加了两条记录

编辑于 2024-12-15 10:19・重庆
写下你的评论...

3 条评论
默认
最新
金子涵

有高可用功能吗?

01-23 · 天津
welldone

不是可以在另一个dns-server中创建Secondary Zone吗?

05-27 · 广东
hall
作者
你可以试试,我觉得够呛.

保守点还是 coreDNS 还是 bind9 吧.
01-23 · 安徽
想来知乎工作?请发送邮件到 jobs@zhihu.com
登录即可查看 超5亿 专业优质内容
超 5 千万创作者的优质提问、专业回答、深度文章和精彩视频尽在知乎。