内网部署 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 是关于服务器的设置
 - 知乎_files/v2-b3f5c3bbd73d9a851a66486cc8299ace_1440w.jpg)
在 Setting 里面关注两个地方
- Recursion 关于服务器递归查询的设置
- Forwarders 上游 DNS 服务器设置
 - 知乎_files/v2-eb22b4c9c347d091b385db8da9ff844e_1440w.jpg)
Recursion
改成第二个 Allow Recursion ,允许递归,接收任何地方的请求.
Proxy & Forwarders
- Quick Select 那里快速选择上游的 DNS 服务器(选一个你能连接的)
- Forwarder Protocol 选择你用什么协议转发请求
 - 知乎_files/v2-90f409593c6dc5997a7bc27179f14e83_1440w.jpg)
这一页的最下方,给出两个官方文档链接
 - 知乎_files/v2-dc9d1aeda4e3e80cb610aaddc41b39f4_1440w.jpg)
Add Zone
我们点击右上角 Add Zone 开始添加第一个 Zone.
Zone 我们不去介绍,这是 DNS 服务器基本知识.
 - 知乎_files/v2-355f7f5fb2295da2f60c4e506f303eaa_1440w.jpg)
我们添加的第一个 zone 是关于域名 hellodns.intranet
的.
 - 知乎_files/v2-0b75963bead7a90784de6ea56908cbb8_1440w.jpg)
关于类型的介绍
编号 | 类型 | 描述 | 用途 | 适用场景 |
---|---|---|---|---|
1 | Primary Zone | 这是默认选项,用于配置该服务器作为主 DNS 服务器。 | 自定义并维护整个 DNS 区域数据,提供权威 DNS 响应。 | 新建一个 DNS 区域,所有记录都在此服务器上编辑和管理。 |
2 | Secondary Zone | 这类区域会从另一个主 DNS 服务器中复制数据(也称为从属 DNS 服务器)。 | 用于高可用和负载均衡,定期从 Primary Zone 同步数据。 | 做为主 DNS 服务器的冗余备份或从主服务器复制记录。 |
3 | Stub Zone | 仅存储其他 DNS 区域的 NS 记录和相关 Glue Record(名称服务器的 IP)。 | 用于快速查找特定区域的权威服务器,而不用存储整个区域的数据。 | 大型环境中优化递归查询路径。 |
4 | Conditional Forwarder Zone | 将某些特定域名的 DNS 查询转发到指定的 DNS 服务器。 | 定制 DNS 解析路径,用于处理跨组织或跨网络的域名。 | 跨域环境中的专用解析。 |
5 | Secondary Conditional Forwarder Zone | 类似 Conditional Forwarder,但以 Secondary 方式存在,会从另一个 DNS 服务器中同步。 | 在特定域的条件转发基础上添加冗余同步机制。 | 较大的环境中需要转发并保持高可用性。 |
6 | Catalog Zone | 用于动态管理和分发一组 DNS 区域的元信息。 | 自动化管理多个区域的 DNS 数据。 | 需要管理多个子域或大量子域环境的自动化。 |
7 | Secondary Catalog Zone | Catalog Zone 的从属版本,用于同步并缓存元信息。 | 从另一个 DNS 服务器复制 Catalog Zone 的数据。 | 大规模分布式环境中动态更新 Catalog。 |
8 | Secondary ROOT Zone (RFC 8806) | 配置该服务器同步和缓存根区域的数据。 | 提高递归 DNS 查询速度,避免直接查询根服务器。 | 大型 DNS 服务商或有高性能需求的网络环境。 |
点击 Add Record 可以添加对域名和二级域名的 DNS 记录.
 - 知乎_files/v2-251e3c302e0fd9de8592bb85822a2a8e_1440w.jpg)
我们添加的 DNS 记录有以下两个.
TTL 统一设置为 60.
hellodns.intranet - 192.168.145.10
api.hellodns.intranet - 192.192.145.11
 - 知乎_files/v2-aca3e3f4af2313afae30ce9e45e08112_1440w.jpg)
 - 知乎_files/v2-fbf34bbd9d6097afa680c6536041c8bf_1440w.jpg)
import Zone file
generate Zone file
使用 zone 文件管理,是更专业的做法.
在这里,我们不用手写 zone 文件. (太麻烦了)
我们使用 zone 文件生成器.
我们用搜索出来的第一个结果,来生成 zone 文件.
https://nimmneun.com/toolbox/bind-zone-file-generator/
 - 知乎_files/v2-5c7235476ad79bbab0d9d8cab1d18941_1440w.jpg)
我们为 hellozone.intranet
生成 zone 文件
生成出来的部分文件内容.
$TTL 7200
api IN A 192.168.145.13
log IN A 192.168.145.14
import zone file
选择导入 zone
 - 知乎_files/v2-f0a2a980fe08ba7cf6f2cd1a47e4a79e_1440w.jpg)
复制粘贴,不要勾选,下面的 Overwrite .
因为我们只是用了一部分 zone 文件
 - 知乎_files/v2-394ce8701d427070bb15368ecdcfc01f_1440w.jpg)
返回界面,你就会看到添加了两条记录
 - 知乎_files/v2-39eb130356ee03e07b84dda70307aa27_1440w.jpg)
编辑于 2024-12-15 10:19・重庆
有高可用功能吗?
不是可以在另一个dns-server中创建Secondary Zone吗?
保守点还是 coreDNS 还是 bind9 吧.