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.

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

For example:

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

Thank you! :)

share|improve this question
    
Which system do you use? –  kockiren Aug 2 '12 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) –  RedGrittyBrick Aug 2 '12 at 7:48
    
You are asking because you want to use something like Tunlr DNS? –  Robert Niestroj Aug 2 '12 at 7:54
    
If you use for example pfsense you can set new IPs for Domains. –  kockiren Aug 2 '12 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;
forwarders{
  192.168.1.1;
};
zone "example.com" IN {
type forward;
    forwarders {8.8.8.8;};
};

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 192.168.1.2 netmask 255.255.255.0
sudo ifconfig eth0:0 alias host 192.168.2.2 netmask 255.255.255.0

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

route add -host 192.168.1.1 dev eth0:0
route add -host www.example.com dev eth0:0
route add -host 8.8.8.8 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.

share|improve this answer

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.