Back

/ 3 min read

Network Command Quick Book 🌐

BASICS

Common DNS record types

  • A maps a domain name to an IPv4 address.
  • AAAA maps a domain name to an IPv6 address.
  • MX tells email where to go for a domain.
  • NS shows the authoritative nameservers for a domain.
  • SOA stores primary zone information like the main nameserver and DNS timing values.
  • TXT stores free-form text, often used for SPF, DKIM, and verification tokens.
  • PTR is used for reverse DNS, mapping an IP address back to a hostname.

Quick examples

  • Aexample.com93.184.216.34
  • AAAAexample.com2606:2800:220:1:248:1893:25c8:1946
  • MXgmail.comgmail-smtp-in.l.google.com
  • NSexample.coma.iana-servers.net
  • TXTexample.com"v=spf1 -all"

BASIC LOOKUP

Query the default A record for a domain

Terminal window
dig example.com

Example output:

; <<>> DiG 9.10.6 <<>> example.com
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 300 IN A 93.184.216.34
;; Query time: 24 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)

RECORD TYPES

Query an A record explicitly

Terminal window
dig example.com A

Example output:

;; ANSWER SECTION:
example.com. 300 IN A 93.184.216.34

Query an AAAA record for IPv6

Terminal window
dig example.com AAAA

Example output:

;; ANSWER SECTION:
example.com. 300 IN AAAA 2606:2800:220:1:248:1893:25c8:1946

Query mail exchange records

Terminal window
dig gmail.com MX

Example output:

;; ANSWER SECTION:
gmail.com. 300 IN MX 5 gmail-smtp-in.l.google.com.
gmail.com. 300 IN MX 10 alt1.gmail-smtp-in.l.google.com.

Query nameserver records

Terminal window
dig example.com NS

Example output:

;; ANSWER SECTION:
example.com. 172800 IN NS a.iana-servers.net.
example.com. 172800 IN NS b.iana-servers.net.

Query the start of authority record

Terminal window
dig example.com SOA

Example output:

;; ANSWER SECTION:
example.com. 3600 IN SOA ns.icann.org. noc.dns.icann.org. 2025010101 7200 3600 1209600 3600

Query TXT records

Terminal window
dig example.com TXT

Example output:

;; ANSWER SECTION:
example.com. 300 IN TXT "v=spf1 -all"

SHORT OUTPUT

Show only the answer section

Terminal window
dig example.com +short

Example output:

93.184.216.34

Show only short MX answers

Terminal window
dig gmail.com MX +short

Example output:

5 gmail-smtp-in.l.google.com.
10 alt1.gmail-smtp-in.l.google.com.
20 alt2.gmail-smtp-in.l.google.com.

USING A SPECIFIC DNS SERVER

Ask Google Public DNS directly

Terminal window
dig @8.8.8.8 example.com

Example output:

;; SERVER: 8.8.8.8#53(8.8.8.8)
;; ANSWER SECTION:
example.com. 300 IN A 93.184.216.34

Ask Cloudflare DNS directly

Terminal window
dig @1.1.1.1 example.com AAAA

Example output:

;; SERVER: 1.1.1.1#53(1.1.1.1)
;; ANSWER SECTION:
example.com. 300 IN AAAA 2606:2800:220:1:248:1893:25c8:1946

REVERSE LOOKUP

Resolve an IP address back to a host name

Terminal window
dig -x 8.8.8.8

Example output:

;; ANSWER SECTION:
8.8.8.8.in-addr.arpa. 1800 IN PTR dns.google.

TRACE DNS RESOLUTION

Trace the full resolution path from the root servers

Terminal window
dig example.com +trace

Example output:

. 518400 IN NS a.root-servers.net.
com. 172800 IN NS a.gtld-servers.net.
example.com. 172800 IN NS a.iana-servers.net.
example.com. 300 IN A 93.184.216.34

CHECK ALL SECTIONS

Display answer, authority, and additional sections clearly

Terminal window
dig example.com +noall +answer +authority +additional

Example output:

example.com. 300 IN A 93.184.216.34
a.iana-servers.net. 172800 IN A 199.43.135.53
b.iana-servers.net. 172800 IN A 199.43.133.53

COMMON FLAGS

Skip comments and show only records

Terminal window
dig example.com +nocmd +noquestion +nocomments +nostats

Example output:

example.com. 300 IN A 93.184.216.34
Terminal window
dig example.com +dnssec

Example output:

;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

PRACTICAL CHECKS

Verify a website points to the expected IP

Terminal window
dig myapp.example.com +short

Example output:

203.0.113.10

Verify a domain has mail routing configured

Terminal window
dig myapp.example.com MX +short

Example output:

10 mail.myapp.example.com.

Verify a TXT record such as SPF or domain verification

Terminal window
dig myapp.example.com TXT +short

Example output:

"v=spf1 include:_spf.example.net ~all"

NSLOOKUP EXAMPLES

Use nslookup for a basic lookup

Terminal window
nslookup example.com

Example output:

Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name: example.com
Address: 93.184.216.34

Query a specific record type

Terminal window
nslookup -type=MX gmail.com

Example output:

gmail.com mail exchanger = 5 gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.

Query using a specific DNS server

Terminal window
nslookup example.com 8.8.8.8

Example output:

Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: example.com
Address: 93.184.216.34

HOST EXAMPLES

Use host for a basic lookup

Terminal window
host example.com

Example output:

example.com has address 93.184.216.34
example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946

Use host for MX records

Terminal window
host -t MX gmail.com

Example output:

gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.

Reverse lookup an IP address

Terminal window
host 8.8.8.8

Example output:

8.8.8.8.in-addr.arpa domain name pointer dns.google.

See which DNS server answered you

With dig:

Terminal window
dig example.com

Look for:

;; SERVER: 192.168.1.1#53(192.168.1.1)

With nslookup:

Terminal window
nslookup example.com

Look for:

Server: 192.168.1.1
Address: 192.168.1.1#53

With host:

Terminal window
host -v example.com

Look for output similar to:

Using domain server:
Name: 192.168.1.1
Address: 192.168.1.1#53