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.
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)- A5% (1)
- B81% (17)
- C10% (2)
- D5% (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.
`+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.
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.
`+answer` and `+mostatus` are not standard `dig` command options for controlling output for scripting in this manner.
`+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
Community Discussion
No community discussion yet for this question.