我正在编写一个脚本,需要使用用户指定的 DNS 服务器查询 DNS 记录。DNS 服务器可以采用任何协议,包括 UDP、TCP、DNS over HTTPS (DoH) 和 DNS over TLS (DoT)。
我知道dig能够处理 UDP 和 TCP(带+tcp标志)的DNS 。有没有办法可以使用dig或其他工具来查询 DoH 和 DoT 服务器?
我更喜欢已经存在的流行工具,curl这样我的脚本会更便携,但也欢迎其他建议。
Sho*_* Ya 14
我没有找到同时满足这两个目的的单一工具,但我确实找到了使用它们的方法。
查询DoH有两种方式:
# json
curl -H 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=example.com&type=A' | jq .
# dns wireformat
curl -H 'accept: application/dns-message' 'https://dns.google/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | hexdump -c
Run Code Online (Sandbox Code Playgroud)
对于DOT,您可以使用kdig所提供的工具knot。命令行类似于dig:
apt-get install knot-dnsutils
# For macOS:
# brew install knot
kdig -d @8.8.8.8 +tls-ca +tls-host=dns.google.com example.com
Run Code Online (Sandbox Code Playgroud)
其中8.8.8.8是 tls 主机的预解析地址 ( dns.google.com)。
更新:这是一个工具 ( https://github.com/ameshkov/dnslookup ),它本身支持所有主要的 DNS 协议,并且能够生成机器可读的输出。
卷曲有官方卫生部自7.62.0版本支持(问题是如何使你的目标端点的多有卷曲UPTODATE到这个版本。)
通过使用--doh-url选项来使用它。例子:
curl --doh-url https://cloudflare-dns.com/dns-query https://www.google.com
Run Code Online (Sandbox Code Playgroud)
参见:https : //github.com/curl/curl/wiki/DOH-implementation https://daniel.haxx.se/blog/2018/09/06/doh-in-curl/
小智 6
如果 dig 被编译为支持它 +tls:
dig @127.0.0.1 google.com +tls
; <<>> DiG 9.17.8 <<>> @127.0.0.1 google.com +tls
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54991
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 065928dae0bd1d28010000005fdd61d904c6723221991bf3 (good)
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 300 IN A 172.217.0.238
;; Query time: 1123 msec
;; SERVER: 127.0.0.1**#853**(127.0.0.1) **(TLS)**
;; WHEN: Sat Dec 19 02:13:45 UTC 2020
;; MSG SIZE rcvd: 83
Run Code Online (Sandbox Code Playgroud)
除了 DoT(正如其他用户在这里提到的)之外,最新版本dig还支持使用该+https标志进行 DoH 查询。
+https[=value], +nohttps
This option indicates whether to use DNS over HTTPS (DoH) when querying name
servers. When this option is in use, the port number defaults to 443. The
HTTP POST request mode is used when sending the query.
If value is specified, it will be used as the HTTP endpoint in the query URI;
the default is /dns-query. So, for example, dig @example.com +https will use
the URI https://example.com/dns-query.
Run Code Online (Sandbox Code Playgroud)
例子,
dig @cloudflare-dns.com +https foobar.com
Run Code Online (Sandbox Code Playgroud)
通过声明+https,将通过端口 443 上的 HTTPS 向默认端点dig查询提供的 DNS 服务器域 ( ) 。cloudflare-dns.com/dns-query
实际上,上述命令将发送一个 DoH (POST) 请求foobar.com:
有一些选项可以切换到 GET 请求、声明不同的端点等。请阅读与 DoH 相关的这些查询选项的手册页:
+https+https-get+https-post+http-plain+http-plain-get+http-plain-post| 归档时间: |
|
| 查看次数: |
9242 次 |
| 最近记录: |