Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

According to the man page, host ought to query "the server or servers listed in /etc/resolv.conf," but it only uses the first entry in that file:

thefourthtower:$cat /etc/resolv.conf
thefourthtower:$host thefourthtower
Host thefourthtower not found: 3(NXDOMAIN)
thefourthtower:$host thefourthtower has address

The 2wire bit comes from a 2Wire modem/router. AT&T (or 2Wire?) have equipped the thing with very poor firmware and its DNS server (cache) is generally slower than Google Public DNS, a problem compounded by AT&T's own flaky DNS servers (no option for alternate servers).

Can I get host or nslookup to use further /etc/resolv.conf entries (and avoid specifying servers manually)?

Or is the only solution to manually map hosts in /etc/hosts, given the desired ordering of the resolv.conf entries?


Nothing in the above implies that I think Google's nameserver should know about my local hosts.

I am asking: can one use a certain nameserver for local names only (since a name like 'thefourthtower' must be local)?

It looks like the answer is NO, and I must run a nameserver on my machine, because the extant local nameserver is so poor.

share|improve this question

The host command uses the resolver library, and that library uses the nameserver entries in /etc/resolv.conf in order, but only on failure. The purpose of multiple entries is for redundancy, in case the primary server fails for some reason. But it the primary server provides a response, whether positive or negative (e.g. NXDOMAIN), then the other nameserver entries are not used. You can have up to three, for triple redundancy.

External name server like Googles will not know about your local host names. You should put those in your /etc/hosts file, or run a local name server. Running a local name server has the advantage of caching DNS lookups, making future or repeat lookups much faster.

I use dnsmasq as a local DNS and cache. It really helps a lot. Just set your /etc/resolv.conf to use first (or only) nameserver, and configure dnsmasq to user your ISP upstream servers. Even if your ISP is slow, your local cache will compensate most of the time.

share|improve this answer

Remove the first two nameserver entries from /etc/resolv.conf if they do not know about hosts on your LAN or about the domain used locally.

The NXDOMAIN response might be because isn't a registered domain name that can be used on the internet.

$ dig any

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_5.3 <<>> any
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 7984
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;             IN      ANY

;; AUTHORITY SECTION:              1200    IN      SOA 2007041700 3600 600 604800 1200

;; Query time: 209 msec
;; WHEN: Tue Aug 30 13:29:23 2011
;; MSG SIZE  rcvd: 95

Note that the authoritative nameservers for say there is no such domain as I guess it is a convenience used by 2wire products at the LAN level only. is a Google nameserver and should not be expected to know about hosts on your private LAN and the somewhat strange configuration choices made by your 2wire router.

The name of the computer thefourthtower should appear in it's own /etc/hosts table (which you should arrange to be consulted before DNS) and really ought to be known to the DNS nameserver on your LAN (i.e. your 2wire router).

Does your /etc/nsswitch.conf contain hosts: files dns ?

share|improve this answer
I don't believe nsswitch.conf is respected by host since the entry in /etc/hosts exists. – reve_etrange Aug 31 '11 at 9:27
@reve: true "host is a simple utility for performing DNS lookups" but I expect you are only using host to diagnose a name-resolution problem with an application. Applications that use gethostbyname() will be affected by nsswitch.conf. – RedGrittyBrick Aug 31 '11 at 9:33

You can use the following code to query all name servers in your /etc/resolv.conf:

grep '^nameserver' /etc/resolv.conf | cut -c 12- | xargs -i host [HOSTNAME] {}

Or, if you prefer dig(1):

grep '^nameserver' /etc/resolv.conf | cut -c 12- | xargs -i dig @{} [HOSTNAME]
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .