
ユーザーが指定した DNS サーバーを使用して DNS レコードを照会する必要があるスクリプトを作成しています。DNS サーバーは、UDP、TCP、DNS over HTTPS (DoH)、DNS over TLS (DoT) など、任意のプロトコルである可能性があります。
dig
UDP および TCP (フラグ付き) の DNS を処理できることはわかっています。DoHおよび DoT サーバーを照会するために+tcp
使用できる方法または他のツールはありますか?dig
私は、スクリプトの移植性を高めるために、既存の人気ツールのようなツールを好みますcurl
が、他の提案も歓迎します。
答え1
両方の目的にかなう単一のツールは見つかりませんでしたが、それらを使用する方法は見つかりました。
DoH をクエリする方法は 2 つあります。
# 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
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
ここで、 は8.8.8.8
TLS ホストの事前に解決されたアドレスです ( dns.google.com
)。
更新: ここにツールがあります (https://github.com/ameshkov/dnslookup) は、すべての主要な DNS プロトコルを独自にサポートし、機械可読な出力を生成できます。
答え2
カール公式のドハバージョン 7.62.0 以降のサポート (問題は、ターゲット エンドポイントのうち、このバージョンに curl が最新の状態になっているものがいくつあるかです)
オプションを活用してご使用ください--doh-url
。例:
curl --doh-url https://cloudflare-dns.com/dns-query https://www.google.com
見る: https://github.com/curl/curl/wiki/DOH-実装 https://daniel.haxx.se/blog/2018/09/06/doh-in-curl/
答え3
答え4
DoT に加えて (ここで他のユーザーが言及しているように)、最新バージョンでは、フラグdig
を使用して DoH クエリもサポートされます+https
。
+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.
例、
dig @cloudflare-dns.com +https foobar.com
を宣言すると+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