Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Can I configure resolv.conf to use a specific nameserver for a domain?



I don't want to list * in /etc/hosts; I don't want to install a DNS server locally (dnsmasq -S /; and I don't want the DNS server to serve other domains.

share|improve this question

2 Answers 2

You can't. The resolver is not designed that way. You'd have to write your own resolver and either preload it into your applications or use NSS to have it examined first.

share|improve this answer
could i add this feature to the resolver and submit a patch? is this part of libc? – Jayen Oct 31 '11 at 7:06
I recommend not screwing with the existing resolver. And with NSS, there's no need to anyway. – Ignacio Vazquez-Abrams Oct 31 '11 at 7:16
Errr actually that would be a useful adition. Something along the lines os OS X where you can create a /etc/resolver/ and then will be resolved thru the nameservers specified in that file... – Server Horror Oct 31 '11 at 12:35
And further I do recommend fiddling with stuff!. Without people screwing around there won't be any progress! – Server Horror Oct 31 '11 at 12:37

This is indeed a common use case when one has more than one network cnnection, e.g. an internet connection (for the generic traffic) and a vpn connection (just for traffic to a company or remote site).

This is a valid example for the question of the OP. I know no operating system (excluding OSX as I've learned above) which can handle this problem from stock. Having linux, one solution may be using dnsmasq with resolvconf. Resolvconf keeps track on all the different domains and namserver and generates a cfg for dnsmasq. Dnsmasq includes this cfg. The local system then uses dnsmasq as nameserver.

In a more static scenario, one could spare resolvconf and use dnsmasq, only.

And yepp, this is a necro thread, but hence there is no advance in the last 3 years, I resurrect it to get the focus back on this quite old, but still unsolved problem.

share|improve this answer
to add to the answer above, install dnsmasq, setup resolve.conf to use and add lines in /etc/dnsmasq.conf such as: server=/ – DerekC Dec 24 '14 at 10:39

Your Answer


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.