RH: Resolve hostname / IP address with ‘host’ and ‘dig’ without fqdn

 

So you want to resolve a hostname with ‘host’ or with ‘dig’.

We know that server [ test.example.com ] has ip address [ 10.0.0.55 ]

Content of /etc/resolve.conf ( where 10.0.0.5 = ns1.example.com and 10.0.0.6 = ns2.example.com )

domain example.com
search example.com
nameserver 10.0.0.5
nameserver 10.0.0.6
options attempt:2
options timeout:5

 

Resolving with command ‘host’,

# host test
test.example.com has address 10.0.0.55

 

Resolving with command ‘dig’

# dig test
; <<>> DiG 9.7.3-P3 <<>> test
;; global options: +cmd
;; connection timed out; no servers could be reached

The reason why ‘dig’ could not resolve the ip address of ‘test’ is because ‘dig’ won’t look
at the search option in /etc/resolve.conf

Looking at the manual page it says the following :

+[no]search
Use [do not use] the search list defined by the searchlist or
domain directive in resolv.conf (if any). The search list is not
used by default.

 

So by adding the ‘+search’ option as an argument it will resolve the ipaddress :

# dig +search test

; <<>> DiG 9.7.3-P3 <<>> +search phoenix
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34451
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0

;; QUESTION SECTION:
;test.example.com.         IN      A

;; ANSWER SECTION:
test.example.com.  3337    IN      A       10.0.0.55

;; AUTHORITY SECTION:
example.com.          3337    IN      NS      ns1.example.com.
example.com.          3337    IN      NS      ns2.example.com.

;; Query time: 0 msec
;; SERVER: 10.0.0.5#53(10.0.0.5)
;; WHEN: Tue Jul  8 16:47:58 2014
;; MSG SIZE  rcvd: 93

 

It is possible to set per-user defaults for dig via ${HOME}/.digrc. This file is read and any
options in it are applied before the command line arguments.

For example :

# cat /root/.digrc
+search

 

 

Leave a comment

Your email address will not be published.


*


Fix this before you comment on this post * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.