跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 建立自有递归 DNS 服务器 - 让 DNS 解析无限速

发表于

简介

由于最近国内的阿里的公共 DNS 服务器也进行了限速,之前腾讯的 DNS 也限速了。

所以本教程教大家自建一个递归 DNS 服务器,让所有 DNS 查询请求向权威服务器进行查询。

DNS 服务器软件使用 Unbound

系统使用 Rocky Linux 8/9

关闭防火墙和 SElinux

!注意:国内递归 DNS 服务器若对公网开放,需要进行备案。

递归 DNS 服务器与权威 DNS 服务器

1.权威 DNS:

权威 DNS 是经过上一级授权对域名进行解析的服务器,同时它可以把解析授权转授给其他人,如 COM 顶级服务器可以授权 dns.com 这个域名的的权威服务器为 NS.ABC.COM ,同时 NS.ABC.COM 还可以把授权转授给 NS.DDD.COM ,这样 NS.DDD.COM 就成了 ABC.COM 实际上的权威服务器了。平时我们解析域名的结果都源自权威 DNS 。比如 dns.com 的权威 DNS 服务器就是 ns1.dns.comns2.dns.com 。然后通过 ns1.dns.com 即可查询域名的具体 IP 地址或其他记录。

2.递归 DNS:

负责接受用户对任意域名查询,并返回结果给用户。递归 DNS 可以缓存结果以避免重复向上查询。我们平时使用最多的就是这类 DNS ,他对公众开放服务,一般由网络运营商提供,大家都自己可以架递归 DNS 提供服务。递归 DNS 一定要有可靠的互联网连接方可使用。比如谷歌的 8.8.8.8 和 8.8.4.4 以及 114 的 114.114.114.114 和 114.114.115.115 都属于这一类 DNS 。你本地电脑上设置的 DNS 就是这类 DNS 。

3.转发 DNS:

负责接受用户查询,并返回结果给用户。但这个结果不是按标准的域名解析过程得到的,而是直接把递归 DNS 的结果转发给用户。它也具备缓存功能。他主要使用在没有直接的互联网连接,但可以连接到一个递归 DNS 那里,这时使用转发 DNS 就比较合适。其缺陷是:直接受递归 DNS 的影响,服务品质较差。比如我们用的路由器里面的 DNS 就是这一类,用路由器的朋友可以看下本地电脑的 DNS 一般都是 192.168.1.1 。

查看 DNS 递归服务器解析过程跟踪

安装工具、关闭防火墙、关闭 SELinux


systemctl disable --now firewalld

sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config && setenforce 0

dnf install tree vim bash-completion tar bind-utils -y


dig 查看

dig +trace baidu.com


; <<>> DiG 9.11.36-RedHat-9.11.36-5.el8_7.2 <<>> +trace baidu.com
;; global options: +cmd
.			9981	IN	NS	g.root-servers.net.
.			9981	IN	NS	j.root-servers.net.
.			9981	IN	NS	c.root-servers.net.
.			9981	IN	NS	m.root-servers.net.
.			9981	IN	NS	i.root-servers.net.
.			9981	IN	NS	k.root-servers.net.
.			9981	IN	NS	b.root-servers.net.
.			9981	IN	NS	f.root-servers.net.
.			9981	IN	NS	d.root-servers.net.
.			9981	IN	NS	l.root-servers.net.
.			9981	IN	NS	e.root-servers.net.
.			9981	IN	NS	h.root-servers.net.
.			9981	IN	NS	a.root-servers.net.

# 通过 114 获取到 root C 的 IP 地址

;; Received 824 bytes from 114.114.114.114#53(114.114.114.114) in 0 ms

com.			172800	IN	NS	a.gtld-servers.net.
com.			172800	IN	NS	d.gtld-servers.net.
com.			172800	IN	NS	l.gtld-servers.net.
com.			172800	IN	NS	c.gtld-servers.net.
com.			172800	IN	NS	m.gtld-servers.net.
com.			172800	IN	NS	h.gtld-servers.net.
com.			172800	IN	NS	e.gtld-servers.net.
com.			172800	IN	NS	j.gtld-servers.net.
com.			172800	IN	NS	b.gtld-servers.net.
com.			172800	IN	NS	i.gtld-servers.net.
com.			172800	IN	NS	g.gtld-servers.net.
com.			172800	IN	NS	f.gtld-servers.net.
com.			172800	IN	NS	k.gtld-servers.net.

# 通过 root C 服务器,获取到所有.com 权威服务器

;; Received 1197 bytes from 192.33.4.12#53(c.root-servers.net) in 197 ms

baidu.com.		172800	IN	NS	ns2.baidu.com.
baidu.com.		172800	IN	NS	ns3.baidu.com.
baidu.com.		172800	IN	NS	ns4.baidu.com.
baidu.com.		172800	IN	NS	ns1.baidu.com.
baidu.com.		172800	IN	NS	ns7.baidu.com.

# 通过.com 权威服务器,获取到 baidu.com 的权威服务器。

;; Received 845 bytes from 192.43.172.30#53(i.gtld-servers.net) in 237 ms

baidu.com.		600	IN	A	39.156.66.10
baidu.com.		600	IN	A	110.242.68.66
baidu.com.		86400	IN	NS	dns.baidu.com.
baidu.com.		86400	IN	NS	ns7.baidu.com.
baidu.com.		86400	IN	NS	ns4.baidu.com.
baidu.com.		86400	IN	NS	ns2.baidu.com.
baidu.com.		86400	IN	NS	ns3.baidu.com.

# 通过 ns3.baidu.com 权威服务器,获取到 baidu.com 的 ip 解析为 112.80.248.64

;; Received 356 bytes from 112.80.248.64#53(ns3.baidu.com) in 26 ms

安装

dnf install unbound -y

配置

vim /etc/unbound/unbound.conf

server:
    interface: 0.0.0.0
    interface: ::0
    
    access-control: 0.0.0.0/0 allow
    access-control: ::/0 allow
    
    
# 在 server 下,修改如上配置,监听所有 IPv4 和 IPv6 地址,和允许所有 IPv4 地址和 IPv6 访问使用 DNS 服务器。    

启动和验证

systemctl enable --now unbound

# 启动服务并设置开机启动

systemctl status unbound

# 查看服务状态

dnf install bind-utils -y

dig @localhost www.qq.com

# 安装 dig ,指定本地 dns 服务器,查询域名测试可用性。

dig +short TXT whoami.ds.akahelp.net  @127.0.0.1

# 查询 dns 服务器访问权威服务器使用的公网 IP 。

抓包验证

tcpdump -i eth0  port domain -w ./dns.pcap 

# 可在服务器指定接口抓包 dns 报文进行分析,使用 Wireshark 打开。

博客

https://songxwn.com/

技术交流群

发送邮件到 ➡️ me@songxwn.com

或者关注 WX 公众号:网工格物

微信扫码

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.