Is it possible to configure a domain-depentant nameserver for address-resolution (e.g. resolv.conf)?


nameserver for any domain abc.com
nameserver for any domain cba.com
nameserver for anything else

I am using a modern Debian.

2 Answers 2


You can’t do this with only resolv.conf, but with an intermediary DNS forwarding daemon such as Dnsmasq (packaged in Debian as dnsmasq and related packages).

With Dnsmasq, you’d configure Dnsmasq itself with the list of servers:


and tell it not to look at resolv.conf:


Then you’d change your resolv.conf so it points to the Dnsmasq daemon, by removing all the nameserver entries therein. You’d also need to ensure that any DHCP setup doesn’t overwrite resolv.conf.


Yes. It's been possible for a quarter of a century. What you are looking for is split horizon DNS service, and it is not done by fiddling with /etc/resolv.conf. That configuration file dictates stuff to the DNS client library that is (usually) built into the C library that applications programs link to. That library is simple and does not do complex decisions like working out where to send different queries to based upon their question sections.

It's done by fiddling with the (machine-local or site-local) resolving proxy DNS server that the DNS client libraries are configured to talk to. In concrete terms: The /etc/resolv.conf settings point applications to a resolving DNS proxy server listening on (say) a socket bound to the IPv4 address, and that server is configured, in ways that are specific to the server software, to enact query resolution in the appropriate way. That proxy DNS server, or even the content DNS server(s) that it in its turn talks to, is where all of the split-horizon mechanism resides.

  • In ISC's BIND, this is done with conditional forwarding or with stub zones.
  • In Daniel J. Bernstein's dnscache this is done with servers/domain files.
  • In dnsmasq, this is done in yet another way. As too systemd-resolved. And so forth.

So install one of these server softwares (Debian even having some of them pre-packaged) on your Debian machine, configure the DNS client libraries to use it, and configure it to do split-horizon DNS.

Further reading

You must log in to answer this question.

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