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 [ ]

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

domain example.com
search example.com
options attempt:2
options timeout:5


Resolving with command ‘host’,

# host test
test.example.com has address


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 :

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

;test.example.com.         IN      A

test.example.com.  3337    IN      A

example.com.          3337    IN      NS      ns1.example.com.
example.com.          3337    IN      NS      ns2.example.com.

;; Query time: 0 msec
;; 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



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.