dig
Table of Contents
1. Tools
I named this cheat dig because it's the most popular one, but this is umbrella for drill / nslookup / getent etc.
1.1. dig
# lookup dig apple.com # A record dig mx apple.com # mx record dig +tcp -p 443 djh.im @208.67.220.220 # tcp, custom port, custom dns server(@) # trace dig +trace apple.com
1.2. drill
# lookup drill -t -p 443 djh.im @208.67.220.220 # tcp, custom port, custom dns server(@) # trace drill -TD apple.com # w DNSSEC drill -T apple.com # w/o DNSSEC
- drill doesn't aim to be a 100% drop-in replacement for dig
drill -Q
works similar todig +short
- Does not have
+multiline
likedig
1.2.1. Different records
<
1.3. getent
getent hosts apple.com # get shit from /etc/hosts, this is what you'd get if you type the same in firefox
- Gets you stuff from nsswitch, unlike dig/nslookup which query a dns nameserver.
- This is what you want to see if you made changes to
/etc/hosts
1.3.1. Hosts file format
- The format is
[ip_address] [hostname/domain] [alias]
, You can't put a domain in place(1st col) of theip_address
. System will simply ignore that.
2. Snippets
2.1. Public IP lookup
curl -fSs https://1.1.1.1/cdn-cgi/trace | awk -F= '/ip/ { print $2 }'
2.2. Finding services using TXT records
- Some services use
TXT
records for domain validation - Now domain validation using txt records is debatable
- Suggestion is to use opaque token and do linear search of all txt records on verification side instead of txt record value to be something like
name=value_token
- But using opaque token, as a webmaster you loose track of what that opaque token even refers to!
- Suggestion is to use opaque token and do linear search of all txt records on verification side instead of txt record value to be something like
Just use
drill txt stripe.com
, Example.;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 34543 ;; flags: qr rd ra ; QUERY: 1, ANSWER: 20, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;; stripe.com. IN TXT ;; ANSWER SECTION: stripe.com. 600 IN TXT "3l1wm9pqffwmrbvq2f5tbwjwtb8gjbr7" stripe.com. 600 IN TXT "MS=ms80697640" stripe.com. 600 IN TXT "apple-domain-verification=8kIS0gmJTvILWQuI" stripe.com. 600 IN TXT "atlassian-domain-verification=upLp21qQgja1aHG2gnAb1AmXRqb/zG0UK1a0n3zTSXZg5DgOSttR3i5uzA3T9Cdk" stripe.com. 600 IN TXT "docker-verification=ccde1a0d-8d2c-44b5-9d20-6c4e19113fc9" stripe.com. 600 IN TXT "google-site-verification=PrlpJHdk11CIkPsiXoHEAJevWHAk39JRFAqVSe9l7n0" stripe.com. 600 IN TXT "google-site-verification=ZgGi2-xDdfnaWxdfjn5AqtUS11jKWqSXAV_EHODFzdE"
2.3. See all the records examples!
See (All) DNS Resource Records
# drill -Q <record_name> <record_name>.dns.netmeister.org. # drill -Q txt <record_name>.dns.netmeister.org. # eg. drill -Q a a.dns.netmeister.org. drill -Q txt a.dns.netmeister.org. # 2 txt recs