在 DNS 行业,最知名的命令行工具就是 dig 了;但 dig 一直没有支持 TLS。系统管理员可以配置 stunnel 后用 dig 连接本地 stunnel 服务进行调试。
除了 dig 之外,这里推荐另外一个工具 getdns_query。从 debian 9(stretch) 或者 Ubuntu 18.04 上,可以通过如下命令安装
$ sudo apt install getdns-utils
getdns_query 使用 -L 参数指定通过 TLS 进行查询,TLS 查询缺省连接 853 端口;使用 -m 参数表示校验证书和请求域名匹配;使用 -s 参数表示采用 stub 解析模式,而非缺省的递归查询
$ getdns_query @115.159.131.230~dns.rubyfish.cn -m -s -L -A www.google.com $ getdns_query @47.96.179.163~dns.rubyfish.cn -m -s -L -A www.google.com
最简单的调试命令一行 curl 就能搞定
$ curl -H 'accept: application/dns-json' 'https://rubyfish.cn/dns-query?name=www.google.com&type=A'
上述这种简单的 json 响应只是 Google/Mozilla 的实现方案。
IETF 提出的标准化方案要比 web 原生的 json 格式更复杂一些——在 HTTP 流中包装了 DNS 原始的消息。Facebook 的工程师提供了一个基于 Python3.5+ 的工具 doh-proxy,通过 pip 安装的方法为:
$ sudo apt install python3-pip python3-setuptools python3-wheel $ sudo -H pip3 install doh-proxy
安装后使用 doh-client 命令进行查询,--domain 参数指定 DoH 服务器,--qname 指定查询的域名
$ doh-client --domain dns.rubyfish.cn --qname www.facebook.com --qtype A
以上内容来源于:https://www.rubyfish.cn/dns/cmd/