What's the difference between `dig` and `host` when querying a specific name-server?

Solution 1:

host, dig, and nslookup all share most of the same functionality. In the case you are asking about (asking a particular DNS question to a particular nameserver), dig and host (and indeed nslookup) behave exactly the same.

For DNS troubleshooting, dig is preferred because its output format is more "raw": in its output it directly shows the contents of all 4 fields in the DNS response: question, answer, authority, and additional sections (plus the flags in the header), and also it has more options. host, on the other hand, has a more user-friendly output format.

If you don't happen to need an option that one of the commands has and the others don't, or a piece of information that one of them outputs and the others don't, then it comes down to a matter of preference.

Solution 2:

If you're using the non-FQDN hostname, the results can be different because host will use the search domains in resolv.conf, whereas dig does not by default.

You have to use the +search option if you want dig to use resolv.conf (or add it to ~/.digrc).

For example:

$ host foo
foo.myfqdn.com has address 10.1.2.3

$ dig +short foo
# (no result)

$ dig +short +search foo
10.1.2.3