nerdexam
CompTIA

XK0-005 · Question #357

A lab virtual image is always named pc21.local and in variety of testing situation. The administrator wants to use the IP address pc21.local in a script but is concerned it may change from day to…

The correct answer is B. MYIP =$(dig pc21.local +norecurse +nocomments). To ensure a script always uses the accurate IP address for a host named pc21.local, the administrator should use the dig command with options to retrieve the IP address from DNS.

Scripting, Containers, and Automation

Question

A lab virtual image is always named pc21.local and in variety of testing situation. The administrator wants to use the IP address pc21.local in a script but is concerned it may change from day to day, as the image is rebuilt fairly often. Which of the following should the administrator add to a script to ensure the IP address is always accurate?

Options

  • AMYIP =$(dig pc21.local +short
  • BMYIP =$(dig pc21.local +norecurse +nocomments)
  • CMYIP =$(dig pc21.local + answer + mostatus
  • DMYIP =$(dig pc21.local +authority)

How the community answered

(21 responses)
  • A
    5% (1)
  • B
    81% (17)
  • C
    10% (2)
  • D
    5% (1)

Why each option

To ensure a script always uses the accurate IP address for a host named pc21.local, the administrator should use the `dig` command with options to retrieve the IP address from DNS.

AMYIP =$(dig pc21.local +short

`+short` is also used for scripting, as it outputs only the RDATA, but `+norecurse +nocomments` might be preferred in some contexts for specific output parsing logic, or if the question implicitly seeks a specific level of detail in the DNS response.

BMYIP =$(dig pc21.local +norecurse +nocomments)Correct

The `dig` command performs DNS lookups to resolve hostnames to IP addresses. Using `$(dig pc21.local +norecurse +nocomments)` queries the DNS for `pc21.local`, and the `+norecurse` and `+nocomments` options help produce a cleaner output by suppressing comments and preventing recursive queries, making the response more suitable for parsing in a script to extract the IP address.

CMYIP =$(dig pc21.local + answer + mostatus

`+answer` and `+mostatus` are not standard `dig` command options for controlling output for scripting in this manner.

DMYIP =$(dig pc21.local +authority)

`+authority` only displays the authority section of the DNS response, which lists authoritative name servers, not the host's A record containing its IP address.

Concept tested: DNS lookup; dig command for scripting

Source: https://linux.die.net/man/1/dig

Topics

#DNS resolution#dig command#Scripting#Command-line utilities

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice