1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# `nu_plugin_dns`
[Nushell](http://www.nushell.sh/) plugin that does DNS queries and parses
results into meaningful types. Intended to be a native replacement for
[`dig`](https://en.m.wikipedia.org/wiki/Dig_(command)). Uses the excellent
[`hickory`](https://github.com/hickory-dns/hickory-dns) crates.
## Usage
* All queries by default attempt to validate records with DNSSEC. If records
do not have DNSSEC or the nameserver does not support it, then by default, it
falls back to plain queries. This behavior can be tuned with the `--dnssec`
flag.
* Supported protocols are UDP, TCP, TLS, HTTPS, and QUIC
* If no nameserver address is specified, the system's DNS config is used, or if
none is available, falls back to Google.
### Examples
```
simple query for A / AAAA records
> dns query amazon.com
╭────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │ ╭──────────┬────────────╮ │
│ nameserver │ │ address │ 8.8.8.8:53 │ │
│ │ │ protocol │ udp │ │
│ │ ╰──────────┴────────────╯ │
│ │ ╭───┬───────────────────────────────────┬─────────────────────────┬───────────────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────┬────────────────┬─────────────────────────────────────┬───────╮ │
│ messages │ │ # │ header │ question │ answer │ authority │ additional │ edns │ size │ │
│ │ ├───┼───────────────────────────────────┼─────────────────────────┼───────────────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────┼────────────────┼─────────────────────────────────────┼───────┤ │
│ │ │ 0 │ ╭────────────────────┬──────────╮ │ ╭───────┬─────────────╮ │ [list 0 items] │ ╭───┬─────────────┬──────┬───────┬───────┬───────────────────────────────────────────────╮ │ [list 0 items] │ ╭─────────────┬───────────────────╮ │ 100 B │ │
│ │ │ │ │ id │ 28755 │ │ │ name │ amazon.com. │ │ │ │ # │ name │ type │ class │ ttl │ rdata │ │ │ │ rcode_high │ 0 │ │ │ │
│ │ │ │ │ message_type │ RESPONSE │ │ │ type │ AAAA │ │ │ ├───┼─────────────┼──────┼───────┼───────┼───────────────────────────────────────────────┤ │ │ │ version │ 0 │ │ │ │
│ │ │ │ │ op_code │ QUERY │ │ │ class │ IN │ │ │ │ 0 │ amazon.com. │ SOA │ IN │ 25sec │ ╭─────────┬─────────────────────────────────╮ │ │ │ │ dnssec_ok │ false │ │ │ │
│ │ │ │ │ authoritative │ false │ │ ╰───────┴─────────────╯ │ │ │ │ │ │ │ │ │ mname │ dns-external-master.amazon.com. │ │ │ │ │ max_payload │ 512 B │ │ │ │
│ │ │ │ │ truncated │ false │ │ │ │ │ │ │ │ │ │ │ rname │ root.amazon.com. │ │ │ │ │ opts │ {record 0 fields} │ │ │ │
│ │ │ │ │ recusion_desired │ true │ │ │ │ │ │ │ │ │ │ │ serial │ 2010176156 │ │ │ │ ╰─────────────┴───────────────────╯ │ │ │
│ │ │ │ │ recusion_available │ true │ │ │ │ │ │ │ │ │ │ │ refresh │ 3min │ │ │ │ │ │ │
│ │ │ │ │ authentic_data │ false │ │ │ │ │ │ │ │ │ │ │ retry │ 1min │ │ │ │ │ │ │
│ │ │ │ │ response_code │ No Error │ │ │ │ │ │ │ │ │ │ │ expire │ 1month 5day │ │ │ │ │ │ │
│ │ │ │ │ query_count │ 1 │ │ │ │ │ │ │ │ │ │ │ minimum │ 1min │ │ │ │ │ │ │
│ │ │ │ │ answer_count │ 0 │ │ │ │ │ │ │ │ │ │ ╰─────────┴─────────────────────────────────╯ │ │ │ │ │ │
│ │ │ │ │ name_server_count │ 1 │ │ │ │ ╰───┴─────────────┴──────┴───────┴───────┴───────────────────────────────────────────────╯ │ │ │ │ │
│ │ │ │ │ additional_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ ╰────────────────────┴──────────╯ │ │ │ │ │ │ │ │
│ │ │ 1 │ ╭────────────────────┬──────────╮ │ ╭───────┬─────────────╮ │ ╭───┬─────────────┬──────┬───────┬────────────┬─────────────────╮ │ [list 0 items] │ [list 0 items] │ ╭─────────────┬───────────────────╮ │ 87 B │ │
│ │ │ │ │ id │ 25101 │ │ │ name │ amazon.com. │ │ │ # │ name │ type │ class │ ttl │ rdata │ │ │ │ │ rcode_high │ 0 │ │ │ │
│ │ │ │ │ message_type │ RESPONSE │ │ │ type │ A │ │ ├───┼─────────────┼──────┼───────┼────────────┼─────────────────┤ │ │ │ │ version │ 0 │ │ │ │
│ │ │ │ │ op_code │ QUERY │ │ │ class │ IN │ │ │ 0 │ amazon.com. │ A │ IN │ 2min 15sec │ 205.251.242.103 │ │ │ │ │ dnssec_ok │ false │ │ │ │
│ │ │ │ │ authoritative │ false │ │ ╰───────┴─────────────╯ │ │ 1 │ amazon.com. │ A │ IN │ 2min 15sec │ 54.239.28.85 │ │ │ │ │ max_payload │ 512 B │ │ │ │
│ │ │ │ │ truncated │ false │ │ │ │ 2 │ amazon.com. │ A │ IN │ 2min 15sec │ 52.94.236.248 │ │ │ │ │ opts │ {record 0 fields} │ │ │ │
│ │ │ │ │ recusion_desired │ true │ │ │ ╰───┴─────────────┴──────┴───────┴────────────┴─────────────────╯ │ │ │ ╰─────────────┴───────────────────╯ │ │ │
│ │ │ │ │ recusion_available │ true │ │ │ │ │ │ │ │ │
│ │ │ │ │ authentic_data │ false │ │ │ │ │ │ │ │ │
│ │ │ │ │ response_code │ No Error │ │ │ │ │ │ │ │ │
│ │ │ │ │ query_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ answer_count │ 3 │ │ │ │ │ │ │ │ │
│ │ │ │ │ name_server_count │ 0 │ │ │ │ │ │ │ │ │
│ │ │ │ │ additional_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ ╰────────────────────┴──────────╯ │ │ │ │ │ │ │ │
│ │ ╰───┴───────────────────────────────────┴─────────────────────────┴───────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────┴────────────────┴─────────────────────────────────────┴───────╯ │
╰────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
```
specify query type
> dns query --type CNAME en.wikipedia.org
╭────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │ ╭──────────┬────────────╮ │
│ nameserver │ │ address │ 8.8.8.8:53 │ │
│ │ │ protocol │ udp │ │
│ │ ╰──────────┴────────────╯ │
│ │ ╭───┬───────────────────────────────────┬───────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────┬────────────────┬────────────────┬─────────────────────────────────────┬──────╮ │
│ messages │ │ # │ header │ question │ answer │ authority │ additional │ edns │ size │ │
│ │ ├───┼───────────────────────────────────┼───────────────────────────────┼───────────────────────────────────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────────────────────────┼──────┤ │
│ │ │ 0 │ ╭────────────────────┬──────────╮ │ ╭───────┬───────────────────╮ │ ╭───┬───────────────────┬───────┬───────┬─────────────────┬─────────────────────╮ │ [list 0 items] │ [list 0 items] │ ╭─────────────┬───────────────────╮ │ 74 B │ │
│ │ │ │ │ id │ 60025 │ │ │ name │ en.wikipedia.org. │ │ │ # │ name │ type │ class │ ttl │ rdata │ │ │ │ │ rcode_high │ 0 │ │ │ │
│ │ │ │ │ message_type │ RESPONSE │ │ │ type │ CNAME │ │ ├───┼───────────────────┼───────┼───────┼─────────────────┼─────────────────────┤ │ │ │ │ version │ 0 │ │ │ │
│ │ │ │ │ op_code │ QUERY │ │ │ class │ IN │ │ │ 0 │ en.wikipedia.org. │ CNAME │ IN │ 1hr 35min 58sec │ dyna.wikimedia.org. │ │ │ │ │ dnssec_ok │ false │ │ │ │
│ │ │ │ │ authoritative │ false │ │ ╰───────┴───────────────────╯ │ ╰───┴───────────────────┴───────┴───────┴─────────────────┴─────────────────────╯ │ │ │ │ max_payload │ 512 B │ │ │ │
│ │ │ │ │ truncated │ false │ │ │ │ │ │ │ opts │ {record 0 fields} │ │ │ │
│ │ │ │ │ recusion_desired │ true │ │ │ │ │ │ ╰─────────────┴───────────────────╯ │ │ │
│ │ │ │ │ recusion_available │ true │ │ │ │ │ │ │ │ │
│ │ │ │ │ authentic_data │ false │ │ │ │ │ │ │ │ │
│ │ │ │ │ response_code │ No Error │ │ │ │ │ │ │ │ │
│ │ │ │ │ query_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ answer_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ name_server_count │ 0 │ │ │ │ │ │ │ │ │
│ │ │ │ │ additional_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ ╰────────────────────┴──────────╯ │ │ │ │ │ │ │ │
│ │ ╰───┴───────────────────────────────────┴───────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────┴────────────────┴────────────────┴─────────────────────────────────────┴──────╯ │
╰────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
```
specify query types by numeric ID, and get numeric IDs in output
> dns query --type [5, 15] -c google.com
╭────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │ ╭──────────┬────────────╮ │
│ nameserver │ │ address │ 8.8.8.8:53 │ │
│ │ │ protocol │ udp │ │
│ │ ╰──────────┴────────────╯ │
│ │ ╭───┬──────────────────────────────────────────────┬──────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────┬────────────────┬─────────────────────────────────────┬──────╮ │
│ messages │ │ # │ header │ question │ answer │ authority │ additional │ edns │ size │ │
│ │ ├───┼──────────────────────────────────────────────┼──────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────┼─────────────────────────────────────┼──────┤ │
│ │ │ 0 │ ╭────────────────────┬─────────────────────╮ │ ╭───────┬──────────────────╮ │ [list 0 items] │ ╭───┬─────────────┬────────────────┬───────────────┬──────┬─────────────────────────────────────╮ │ [list 0 items] │ ╭─────────────┬───────────────────╮ │ 89 B │ │
│ │ │ │ │ id │ 20006 │ │ │ name │ google.com. │ │ │ │ # │ name │ type │ class │ ttl │ rdata │ │ │ │ rcode_high │ 0 │ │ │ │
│ │ │ │ │ │ ╭──────┬──────────╮ │ │ │ │ ╭──────┬───────╮ │ │ │ ├───┼─────────────┼────────────────┼───────────────┼──────┼─────────────────────────────────────┤ │ │ │ version │ 0 │ │ │ │
│ │ │ │ │ message_type │ │ name │ RESPONSE │ │ │ │ type │ │ name │ CNAME │ │ │ │ │ 0 │ google.com. │ ╭──────┬─────╮ │ ╭──────┬────╮ │ 1min │ ╭─────────┬───────────────────────╮ │ │ │ │ dnssec_ok │ false │ │ │ │
│ │ │ │ │ │ │ code │ 1 │ │ │ │ │ │ code │ 5 │ │ │ │ │ │ │ │ name │ SOA │ │ │ name │ IN │ │ │ │ mname │ ns1.google.com. │ │ │ │ │ max_payload │ 512 B │ │ │ │
│ │ │ │ │ │ ╰──────┴──────────╯ │ │ │ │ ╰──────┴───────╯ │ │ │ │ │ │ │ code │ 6 │ │ │ code │ 1 │ │ │ │ rname │ dns-admin.google.com. │ │ │ │ │ opts │ {record 0 fields} │ │ │ │
│ │ │ │ │ │ ╭──────┬───────╮ │ │ │ │ ╭──────┬────╮ │ │ │ │ │ │ ╰──────┴─────╯ │ ╰──────┴────╯ │ │ │ serial │ 554750970 │ │ │ │ ╰─────────────┴───────────────────╯ │ │ │
│ │ │ │ │ op_code │ │ name │ QUERY │ │ │ │ class │ │ name │ IN │ │ │ │ │ │ │ │ │ │ │ refresh │ 15min │ │ │ │ │ │ │
│ │ │ │ │ │ │ code │ 0 │ │ │ │ │ │ code │ 1 │ │ │ │ │ │ │ │ │ │ │ retry │ 15min │ │ │ │ │ │ │
│ │ │ │ │ │ ╰──────┴───────╯ │ │ │ │ ╰──────┴────╯ │ │ │ │ │ │ │ │ │ │ expire │ 30min │ │ │ │ │ │ │
│ │ │ │ │ authoritative │ false │ │ ╰───────┴──────────────────╯ │ │ │ │ │ │ │ │ │ minimum │ 1min │ │ │ │ │ │ │
│ │ │ │ │ truncated │ false │ │ │ │ │ │ │ │ │ │ ╰─────────┴───────────────────────╯ │ │ │ │ │ │
│ │ │ │ │ recusion_desired │ true │ │ │ │ ╰───┴─────────────┴────────────────┴───────────────┴──────┴─────────────────────────────────────╯ │ │ │ │ │
│ │ │ │ │ recusion_available │ true │ │ │ │ │ │ │ │ │
│ │ │ │ │ authentic_data │ false │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ ╭──────┬──────────╮ │ │ │ │ │ │ │ │ │
│ │ │ │ │ response_code │ │ name │ No Error │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ code │ 0 │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ ╰──────┴──────────╯ │ │ │ │ │ │ │ │ │
│ │ │ │ │ query_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ answer_count │ 0 │ │ │ │ │ │ │ │ │
│ │ │ │ │ name_server_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ additional_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ ╰────────────────────┴─────────────────────╯ │ │ │ │ │ │ │ │
│ │ │ 1 │ ╭────────────────────┬─────────────────────╮ │ ╭───────┬───────────────╮ │ ╭───┬─────────────┬───────────────┬───────────────┬────────────┬───────────────────────────────────╮ │ [list 0 items] │ [list 0 items] │ ╭─────────────┬───────────────────╮ │ 60 B │ │
│ │ │ │ │ id │ 47130 │ │ │ name │ google.com. │ │ │ # │ name │ type │ class │ ttl │ rdata │ │ │ │ │ rcode_high │ 0 │ │ │ │
│ │ │ │ │ │ ╭──────┬──────────╮ │ │ │ │ ╭──────┬────╮ │ │ ├───┼─────────────┼───────────────┼───────────────┼────────────┼───────────────────────────────────┤ │ │ │ │ version │ 0 │ │ │ │
│ │ │ │ │ message_type │ │ name │ RESPONSE │ │ │ │ type │ │ name │ MX │ │ │ │ 0 │ google.com. │ ╭──────┬────╮ │ ╭──────┬────╮ │ 1min 13sec │ ╭────────────┬──────────────────╮ │ │ │ │ │ dnssec_ok │ false │ │ │ │
│ │ │ │ │ │ │ code │ 1 │ │ │ │ │ │ code │ 15 │ │ │ │ │ │ │ name │ MX │ │ │ name │ IN │ │ │ │ preference │ 10 │ │ │ │ │ │ max_payload │ 512 B │ │ │ │
│ │ │ │ │ │ ╰──────┴──────────╯ │ │ │ │ ╰──────┴────╯ │ │ │ │ │ │ code │ 15 │ │ │ code │ 1 │ │ │ │ exchange │ smtp.google.com. │ │ │ │ │ │ opts │ {record 0 fields} │ │ │ │
│ │ │ │ │ │ ╭──────┬───────╮ │ │ │ │ ╭──────┬────╮ │ │ │ │ │ ╰──────┴────╯ │ ╰──────┴────╯ │ │ ╰────────────┴──────────────────╯ │ │ │ │ ╰─────────────┴───────────────────╯ │ │ │
│ │ │ │ │ op_code │ │ name │ QUERY │ │ │ │ class │ │ name │ IN │ │ │ ╰───┴─────────────┴───────────────┴───────────────┴────────────┴───────────────────────────────────╯ │ │ │ │ │ │
│ │ │ │ │ │ │ code │ 0 │ │ │ │ │ │ code │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ ╰──────┴───────╯ │ │ │ │ ╰──────┴────╯ │ │ │ │ │ │ │ │
│ │ │ │ │ authoritative │ false │ │ ╰───────┴───────────────╯ │ │ │ │ │ │ │
│ │ │ │ │ truncated │ false │ │ │ │ │ │ │ │ │
│ │ │ │ │ recusion_desired │ true │ │ │ │ │ │ │ │ │
│ │ │ │ │ recusion_available │ true │ │ │ │ │ │ │ │ │
│ │ │ │ │ authentic_data │ false │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ ╭──────┬──────────╮ │ │ │ │ │ │ │ │ │
│ │ │ │ │ response_code │ │ name │ No Error │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ code │ 0 │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ ╰──────┴──────────╯ │ │ │ │ │ │ │ │ │
│ │ │ │ │ query_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ answer_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ │ name_server_count │ 0 │ │ │ │ │ │ │ │ │
│ │ │ │ │ additional_count │ 1 │ │ │ │ │ │ │ │ │
│ │ │ │ ╰────────────────────┴─────────────────────╯ │ │ │ │ │ │ │ │
│ │ ╰───┴──────────────────────────────────────────────┴──────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────┴────────────────┴─────────────────────────────────────┴──────╯ │
╰────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
```
pipe name into command
> 'google.com' | dns query
```
```
pipe lists of names into command
> ['google.com', 'amazon.com'] | dns query
```
```
pipe table of queries into command (ignores --type flag)
> [{name: 'google.com', type: 'A'}, {name: 'amazon.com', type: 'A'}] | dns query
```
```
choose a different protocol and/or port
> dns query -p tls -n dns.google -s 8.8.8.8 en.wikipedia.org
> dns query -p https -n cloudflare-dns.com -s 1.1.1.1 en.wikipedia.org
> dns query -p quic -n dns.adguard-dns.com -s 94.140.15.15:853 en.wikipedia.org
```
## Install
```nu
cargo install nu_plugin_dns
nu --commands $"register ($env.CARGO_HOME)/bin/nu_plugin_dns"
```