Is it possible to use different DNS servers based on the ip or the requested hostname?

For example:

  • for www.example.com the DNS server should be used
  • for any other request the DNS server

Thank you! :)

  • Which system do you use?
    – kockiren
    Aug 2, 2012 at 7:48
  • 1
    No, and if there were, it would almost never be a good idea. There almost certainly exist well-established, time-honoured, battle-proven solutions to whatever you are trying to achieve (e.g. zone transfers between DNS servers, split-horizon DNS) Aug 2, 2012 at 7:48
  • You are asking because you want to use something like Tunlr DNS? Aug 2, 2012 at 7:54
  • If you use for example pfsense you can set new IPs for Domains.
    – kockiren
    Aug 2, 2012 at 8:04

1 Answer 1


You could set up your Mac as local DNS forwarder. You have to install bind, configure as your local DNS and configure named.conf (/etc/named.conf).

forward only;
zone "example.com" IN {
type forward;
    forwarders {;};

The other hacky way, which I haven't tested is:

When you having two DNS servers in you /etc/resolve.conf, Mac should decide which DNS is best for you to use based on the routing (I think).

You should assign your Mac into two different networks. The best is to have two connections (LAN+WiFi) or two LAN connections, or at least two gateways, but you could try with one (which will be more complex).

This example is based on one. Basically create two networks like:

sudo ifconfig eth0 host netmask
sudo ifconfig eth0:0 alias host netmask

and then try to re-route your DNS servers and domains to specified interfaces.

route add -host dev eth0:0
route add -host www.example.com dev eth0:0
route add -host dev eth0:0

I don't know if this hacky way will work on one interface, but should work on two.

If you have two gateways (even if it's the same device), more probability it'll work.

If this method doesn't work, sorry (let me know). It should be improved based on some practical go-through.

You must log in to answer this question.

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