Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 192.168.1.254
domain gateway.2wire.net
search gateway.2wire.net
thefourthtower:$host thefourthtower
Host thefourthtower not found: 3(NXDOMAIN)
thefourthtower:$host thefourthtower 192.186.1.254
thefourthtower.gateway.2wire.net has address 192.168.1.74

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?

UPDATE

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
add comment

3 Answers

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 gateway.2wire.net isn't a registered domain name that can be used on the internet.

$ dig gateway.2wire.net any

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5_5.3 <<>> gateway.2wire.net 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

;; QUESTION SECTION:
;gateway.2wire.net.             IN      ANY

;; AUTHORITY SECTION:
2wire.net.              1200    IN      SOA     ns1.2wire.com. hostmaster.2wire.com. 2007041700 3600 600 604800 1200

;; Query time: 209 msec
;; SERVER: 10.0.0.9#53(10.0.0.9)
;; WHEN: Tue Aug 30 13:29:23 2011
;; MSG SIZE  rcvd: 95

Note that the authoritative nameservers for 2wire.net say there is no such domain as gateway.2wire.net. I guess it is a convenience used by 2wire products at the LAN level only.

8.8.8.8 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
add comment

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 127.0.0.1 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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.