DNS Configuration – Domain-Dependent Resolution

dnsresolv.conf

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

e.g.

nameserver 1.2.3.4 for any domain abc.com
nameserver 4.3.2.1 for any domain cba.com
nameserver 1.4.2.3 for anything else

I am using a modern Debian.

Best Answer

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:

server=/abc.com/1.2.3.4
server=/cba.com/4.3.2.1
server=1.4.2.3

and tell it not to look at resolv.conf:

no-resolv

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.

Related Question