How to use dig
jvns.ca
jvns.ca
Sometimes, I want to see the results from getaddrinfo, which are impacted by caching on the host itself and/or OS-specific configuration settings that dig and host know nothing about. (scutil --dns on macOS, systemd-resolvedand nscd on Linux, etc.)
In that case, I usually use ping. e.g., waiting for a DNS change to propagate to a host, I might use:
while :; do ping -c 1 hostname; sleep 1; done getent ahosts myhostEdit: It's not necessarily something to be worried about, just that "strange results" may occur if unaware. E.g. "why and how does 8.8.8.8 resolve a domain-local host?"
Side note: does anyone know why dig's output is so...eye-bleeding? Why does it show so much info by default? +short should be the default. Why the ;; "comment" prefix?
But that moves the question. Why do zone files use ; as comment? Some old assembly dialect? I've not worked much with assembly but it's always been # or //
> @jpmens @bortzmeyer @PowerDNS_Bert @kolkman The ";" was the comment delimiter in the TOPS-20 word, hash was dragged in by the UNIX types
* https://twitter.com/svnr2000/status/659062798681546752
See also RFC 883, "Domain Names - Implementation and Specification":
> ; Semicolon is used to start a comment; the remainder of the line is ignored.
* https://datatracker.ietf.org/doc/html/rfc883
Via:
* https://jpmens.net/2015/10/28/the-semicolon-in-zone-master-f...
* https://twitter.com/paulvixie/status/659934566883328000
Via:
* https://jpmens.net/2015/10/28/the-semicolon-in-zone-master-f...
; <<>> DiG 9.16.20 <<>> -r jvns.ca ;; global options: +cmd ;; Got answer:
just try `host goo.gl 1.1.1.1` or `host -t ns google.com` -- it's the output you'd expect without all the verbosity.
Most of my co-worker prefer host, but continue to be supprised when I use dig and features like reverse lookup or dig @some-dns-server. I’m sure that host can do the same, but few seems to know how.
As for reverse lookups, it's as simple as host <ip-address>
https://datatracker.ietf.org/doc/html/rfc1035.html#section-5...
# rpm -q -f `which host`
bind-utils-9.16.23-1.fc35.x86_64https://bind9.readthedocs.io/en/latest/manpages.html#host-dn...
> host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host prints a short summary of its command-line arguments and options.
https://bind9.readthedocs.io/en/latest/manpages.html#dig-dns...
> dig is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use, and clarity of output. Other lookup tools tend to have less functionality than dig.
I've seen far too many junior admins accidentally change the hostname of a server when checking a DNS record...
Dig is verbose by default, which is usually what I want. It can be made as terse as host with the +short option. host -vt SOA google.com is more typing than dig google.com SOA. Neither dig or host is very good for use by other programs.
Why are they using a root shell for tasks that don't require it in the first place?
If you just want the answer then `host` is just fine - I use both of them a lot - but `dig` really shines when you need to get into the guts of the DNS.
It’s mostly just habit mixed with the difference in inconvenience being quite small
Also doesn’t host use the local nss stack while dig exclusively queries dns?
Reading things like this makes me feel better about the relics in my code that aren't really hurting anything but would take work to remove.
Also, in a hundred years there'll be people making up retronyms for .arpa.
"Uhm maybe it stands for *address reverse protocol association*?"We've already got one! It's been backronymed as "Address and Routing Parameter Area" by IANA[1].
dig +https @dns10.quad9.net fb.com MX
https://www.isc.org/blogs/bind-doh-update-2021/I especially like that last part.
$ jc dig example.com | jq -r '.[].answer[].data'
93.184.216.34
cargo build --release --verbose --target x86_64-unknown-linux-musl --no-default-features --features=with_idna,with_tls,with_https,with_rustls
and... alias dog "dog --edns=show --https --nameserver https://mozilla.cloudflare-dns.com/dns-query"That would have made life so much easier. The state now is that clients cannot even rely on multiple request questions to be answered correctly...and is the reason why every Browser sends out separate DNS questions for A and AAAA and TXT etc.
All the overhead for parsing message compression is also kinda useless when you have only one record with the same labels answered all the time.
And because ANY interacts badly with UDP fragmentation and certain backend database design, and because it has been abused for DDoS attacks, it is increasingly common for it to return a subset of the records that the server has.
So I am afraid there is no realistic way to make ANY mean ALL.
Multiple questions don’t work because DNS packets only have one RCODE so there is no way to signal a mixture of success and failure. I don’t know why the DNS message format has a QDCOUNT field for multiple questions.
Yeah DNS compression is problematic in many ways, but in many cases it allows the answer name(s) to be represented by 0x000C. In another context, the root-servers.net domain looks unnecessarily verbose but having all the servers in the same domain makes good use of compression.
The idea there is to save DNS packets so that you only ask for a pointer (PTR) to a service identifier and get as a response all information that you need (address via A/AAAA, hostname and port via SRV, API version and necessary parameters via TXT etc).
My point was exactly about the QDCOUNT field because its intent clearly was to be able to save unnecessary packets, but in practice, nobody uses it and wastes a lot of bandwidth. Note that technically, servers have to support TCP via port 53, too...but they never actually do :)
As a sidenote: 0x0c is only appearing because it's the start of the label identifier of the first question. This can be a byte pointer to anything, and, if labels of records are crafted maliciously, even lead to an infinite loop or buffer overflow on clients/resolvers with naive implementations (see NAMEWRECK vulnerability [1]).
Regarding the ANY problem and why it's disabled: I think this is the wrong point in the architecture to fix DDoS or amplification attacks and the abuse of a public resolver. ISPs or ASNs could simply block UDP traffic which has a different source/target network. That alone would reduce most of the DDoS traffic and probably fix most of the abuse.
I mean, at some point you have to wonder: What happens when hackers start to use TXT queries to DDoS a target because their buffer size is larger, too? Just disable TXT? I hope you understand my point.
A DNS server could also always block via a throttling mechanism or increase the TTL to limit the bandwidth to a specific target, additionally to the comparison of source/target addresses. If someone with a different origin keeps requesting DNS queries, you can likely assume that it's an amplification attack...there are literally dozens of ways to fix this in a better way than disabling ANY completely.
[1] https://www.forescout.com/blog/forescout-and-jsof-disclose-n...
mDNS is DNS in name only. Yes the wire format is mostly the same but the semantics are not.
> Note that technically, servers have to support TCP via port 53, too...but they never actually do :)
No? I haven't come across a widely used server implementation that doesn't support TCP in a very long time. What server software are you referring to?
> ...there are literally dozens of ways to fix this in a better way than disabling ANY completely.
As fanf2 said, ANY isn't ALL, and so it doesn't do what most people would want it to do anyway.
"A remote unauthenticated user may observe internal network structure, learning information useful for other directed attacks."
On tracing
> So it’ll make about 20 DNS queries
Not sure about this part. Most domains will hit root, tld, x.tlds nameservers, and maybe one more. Most traces should only be 3 to 5 queries.
> So it’ll make about 30 DNS queries. (I checked using tcpdump, it seems to make 2 queries to get A/AAAA records for each of the root nameservers so that’s already 26 queries. I’m not really sure why it does this because it should already have those IPs hardcoded, but it does.)
Basic lookup against specific DNS server:
# dig @8.8.8.8 jvns.ca
PS C:\> Resolve-DnsName -Server 8.8.8.8 -Name jvns.ca
Name Type TTL Section IPAddress
---- ---- --- ------- ---------
jvns.ca AAAA 300 Answer 2606:4700:3031::ac43:b35a
jvns.ca AAAA 300 Answer 2606:4700:3033::6815:5bce
jvns.ca A 300 Answer 104.21.91.206
jvns.ca A 300 Answer 172.67.179.90
Lookup NS type only: # dig ns jvns.ca
PS C:\> Resolve-DnsName -Name jvns.ca -Type NS
Name Type TTL Section NameHost
---- ---- --- ------- --------
jvns.ca NS 20944 Answer art.ns.cloudflare.com
jvns.ca NS 20944 Answer roxy.ns.cloudflare.com
or
PS C:\> Resolve-DnsName jvns.ca NS
Reverse lookup: # dig -x 172.217.13.174
PS C:\> Resolve-DnsName -Server 8.8.8.8 -Name 172.217.13.174
Name Type TTL Section NameHost
---- ---- --- ------- --------
174.13.217.172.in-addr.arpa PTR 21600 Answer yul03s04-in-f14.1e100.net
Reverse lookup using PTR type (it will tab-complete through the available -Type options): PS C:\> Resolve-DnsName -server 8.8.8.8 -Name 174.13.217.172.in-addr.arpa -Type PTR
Name Type TTL Section NameHost
---- ---- --- ------- --------
174.13.217.172.in-addr.arpa PTR 21131 Answer yul03s04-in-f14.1e100.net
The output isn't actually a text table, it's an array of objects, so it's easy to filter and extract data without text parsing: PS C:\> resolve-dnsname google.com ns |% namehost
ns3.google.com
ns1.google.com
ns4.google.com
ns2.google.com
There's also `-TCPOnly`, `-NoRecursion`, `-NoHostsFile` and other options.NB. you can get BIND for Windows, and therefore dig.exe for Windows, at https://www.isc.org/download/
The protocol to look for is IXFR and I’m pretty sure dig does it.
DNS is public data, what harm can come from asking for all of it? It doesn't leak any secrets, it doesn't take a lot of bandwidth or server load, it doesn't give you any power to imitate the domain, and it's nothing you couldn't find by brute-force eventually.
It might speed up some recon "what does this company have?" but DNS caches the world over will know what the company has as soon as users reference it. For all anyone knows they could be malicious DNS caches selling the information behind the scenes. Don't put secrets in public DNS records.
Either way, it was a pleasure to use. And if you know dig, drill will feel very familiar.
To solve this I wrote dug. It's similar to dig, albeit less powerful for info about single hosts, but is specifically designed to monitor large numbers of servers and to 'watch' DNS propagation.
Check it out: https://github.com/unfrl/dug https://dug.unfrl.com
P.S. apparently, nslookup uses its internal resolver, instead of the system's (as dig does). Thus it has been deprecated for some time to avoid confusion [1]. Not sure if anything has changed since.
[1]: https://unix.stackexchange.com/questions/93808/dig-vs-nslook...
dig -p 5353 @224.0.0.251 raspberrypi.localIs there way to find all domains with an A record pointing to a particular IP?
Need it for some market research related to a SaaS product.
However, you can get fairly close, at some expense. You need "passive DNS" which is a product aggregated from large DNS services containing the set of DNS questions and answers they saw over some period (but not who asked the question)
If you can afford to buy this, you can process that data (or your service provider might offer a neat database query that can do it) to find all the A questions whose answer was some particular dotted quad in some period (e.g. last 7 days). Since it's apparently a market research question you likely have a budget and will find this affordable. If it's "market research" only in the sense that somebody in your sales department was idly wondering, well, the answer is they need to pay $$$ to somebody.
Yup, I wrote a DNS server that does just that. So, to find your public IP, you'd type the following:
`dig @ns.sslip.io ip.sslip.io txt +short`
It'll return your public IP.
[removed comments about unrelated services]
[1] - https://unix.stackexchange.com/questions/93808/dig-vs-nslook...
My favorite thing about nslookup is it's clear which server it's querying to get its information.
(SCNR)