Bird
Raised Fist0
Linux CLIscripting~10 mins

nslookup and dig for DNS in Linux CLI - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to look up the IP address of example.com using nslookup.

Linux CLI
nslookup [1]
Drag options to blanks, or click blank then click option'
Aexample.com
Bgoogle.com
Clocalhost
D127.0.0.1
Attempts:
3 left
💡 Hint
Common Mistakes
Using an IP address instead of a domain name.
Typing the command without a domain name.
2fill in blank
medium

Complete the code to query the MX (mail) records of example.com using dig.

Linux CLI
dig [1] example.com
Drag options to blanks, or click blank then click option'
AA
BTXT
CNS
DMX
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'A' instead of 'MX' to find mail servers.
Forgetting to specify the record type.
3fill in blank
hard

Fix the error in the command to perform a reverse DNS lookup for IP 8.8.8.8 using nslookup.

Linux CLI
nslookup [1]
Drag options to blanks, or click blank then click option'
Aarpa.in-addr.8.8.8
B8.8.8.8
C8.8.8.8.in-addr.arpa
Din-addr.arpa.8.8.8.8
Attempts:
3 left
💡 Hint
Common Mistakes
Using the .in-addr.arpa format, which requires -type=PTR (e.g., nslookup -type=PTR 8.8.8.8.in-addr.arpa).
Incorrectly ordering the IP parts.
4fill in blank
hard

Fill both blanks to create a dig command that queries the NS (name server) records for example.com and shows only the answer section.

Linux CLI
dig [1] example.com +[2]
Drag options to blanks, or click blank then click option'
ANS
Bshort
Ctrace
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+all' which shows too much information.
Using the wrong record type like 'A' instead of 'NS'.
5fill in blank
hard

Fill all three blanks to create a command that uses dig to query the TXT records for example.com, uses +short to simplify output, and directs the output to a file named output.txt.

Linux CLI
dig [1] example.com +[2] > [3]
Drag options to blanks, or click blank then click option'
ATXT
Bshort
Coutput.txt
DMX
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong record type like 'MX' instead of 'TXT'.
Forgetting to redirect output to a file.

Practice

(1/5)
1. What is the primary purpose of the nslookup command in Linux?
easy
A. To monitor network traffic
B. To edit DNS server settings
C. To find the IP address of a domain name quickly
D. To create new domain names

Solution

  1. Step 1: Understand nslookup's function

    The nslookup command is used to query DNS to find IP addresses or domain names.
  2. Step 2: Identify the main use case

    Its main use is to quickly find the IP address of a given domain name.
  3. Final Answer:

    To find the IP address of a domain name quickly -> Option C
  4. Quick Check:

    nslookup = quick IP lookup [OK]
Hint: nslookup quickly shows IP for a domain [OK]
Common Mistakes:
  • Thinking nslookup edits DNS settings
  • Confusing nslookup with network monitoring tools
  • Assuming nslookup creates domains
2. Which of the following is the correct syntax to use dig to query the A record of example.com?
easy
A. dig -A example.com
B. dig example.com -t A
C. dig example.com A
D. dig -query=A example.com

Solution

  1. Step 1: Recall dig syntax for record type

    The correct syntax uses the -t option to specify the record type, e.g., dig example.com -t A.
  2. Step 2: Match syntax to options

    dig example.com -t A matches this syntax.
  3. Final Answer:

    dig example.com -t A -> Option B
  4. Quick Check:

    dig -t TYPE domain = query record [OK]
Hint: Use -t to specify record type: dig example.com -t A [OK]
Common Mistakes:
  • Placing record type without -t option
  • Using invalid -A flag
  • Using nonexistent -query flag
3. What will be the output of the command nslookup google.com if the DNS server is reachable and working?
medium
A. The IP address(es) of google.com along with DNS server info
B. A list of all DNS servers on the internet
C. A blank output with no information
D. An error message saying 'server can't find google.com'

Solution

  1. Step 1: Understand nslookup output on success

    If the DNS server is reachable, nslookup returns the IP address(es) of the domain and info about the DNS server used.
  2. Step 2: Eliminate incorrect options

    An error message saying 'server can't find google.com' is an error message, which won't appear if DNS works. A blank output with no information is blank output, unlikely. A list of all DNS servers on the internet is unrelated.
  3. Final Answer:

    The IP address(es) of google.com along with DNS server info -> Option A
  4. Quick Check:

    nslookup success = IP + server info [OK]
Hint: Successful nslookup shows IP and server info [OK]
Common Mistakes:
  • Expecting nslookup to list all DNS servers
  • Thinking nslookup outputs blank on success
  • Confusing error messages with normal output
4. You run dig example.com MX but get no answer section in the output. What is the most likely reason?
medium
A. The dig command syntax is incorrect
B. The DNS server is blocking all queries
C. Your internet connection is down
D. The domain example.com has no MX records configured

Solution

  1. Step 1: Analyze dig output with no answer section

    If dig shows no answer section for MX query, it usually means no MX records exist for that domain.
  2. Step 2: Check other options

    The syntax is correct, eliminating A. Internet down would cause timeout or no response. DNS blocking would cause errors like REFUSED, not empty answer.
  3. Final Answer:

    The domain example.com has no MX records configured -> Option D
  4. Quick Check:

    No MX answer = no MX records [OK]
Hint: No answer section means no such DNS record exists [OK]
Common Mistakes:
  • Assuming syntax error when command is correct
  • Blaming internet connection without checking
  • Thinking DNS server blocks cause empty answers
5. You want to write a script that uses dig to check if a domain has an A record and print "Exists" or "Not Found" accordingly. Which command snippet correctly checks this?
hard
A. if dig example.com A +short | grep -q '.'; then echo "Exists"; else echo "Not Found"; fi
B. if dig example.com A | grep -q 'NXDOMAIN'; then echo "Exists"; else echo "Not Found"; fi
C. if nslookup example.com | grep -q 'Address'; then echo "Exists"; else echo "Not Found"; fi
D. if dig example.com MX +short | grep -q '.'; then echo "Exists"; else echo "Not Found"; fi

Solution

  1. Step 1: Understand how to check A record existence with dig

    Using dig example.com A +short returns IP addresses if A records exist; empty if none.
  2. Step 2: Use grep to check output

    Using grep -q '.' checks if output has any character (non-empty). If yes, print "Exists", else "Not Found".
  3. Step 3: Evaluate options

    if dig example.com A +short | grep -q '.'; then echo "Exists"; else echo "Not Found"; fi correctly uses this logic. if dig example.com A | grep -q 'NXDOMAIN'; then echo "Exists"; else echo "Not Found"; fi checks for NXDOMAIN incorrectly. if nslookup example.com | grep -q 'Address'; then echo "Exists"; else echo "Not Found"; fi uses nslookup, not dig. if dig example.com MX +short | grep -q '.'; then echo "Exists"; else echo "Not Found"; fi checks MX records, not A.
  4. Final Answer:

    if dig example.com A +short | grep -q '.'; then echo "Exists"; else echo "Not Found"; fi -> Option A
  5. Quick Check:

    dig +short output empty means no record [OK]
Hint: Use dig +short and grep for quick record check [OK]
Common Mistakes:
  • Checking wrong record type (MX instead of A)
  • Misinterpreting NXDOMAIN in grep
  • Using nslookup output with dig logic
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard