Is there a way to use a specific DNS for a specific domain?

Solution 1:

This can't be done with the standard DNS resolution provided by *nix (and Windows AFAIK), you need your own DNS server to do this. On *nix dnsmasq is the best choice for this, and you can either run this on every workstation or run it on a server and configure all the workstations to use this.

/etc/resolv.conf:

nameserver 127.0.0.1
nameserver 208.67.222.222
nameserver 208.67.220.220

/etc/dnsmasq.conf:

server=/freenode.net/8.8.8.8
server=/freenode.net/8.8.4.4

Solution 2:

Linux does not support the use of domain-specific DNS servers via resolv.conf. You could potentially work around this by running a caching nameserver (such as BIND or dnsmasq) locally and then configuring explicit forwarders for each domain.

Under OS X, this sort of setting is relatively easy using the scutil command. The common use case for this configuration is to forward DNS requests for a VPN connection to VPN-specific DNS servers, so you'll find this discussed often in concert with, e.g., OpenVPN. This document talks about the scutil command as does this, and a Google search for openvpn and scutil will yield more results.

I'm not sure about Windows. You could presumably use the local DNS server solution for all three platforms if you needed to.


Solution 3:

Under OS X you can use files like /etc/resolver/example.com with content:

nameserver 172.16.5.5

to forward dns requests for *.example.com to 172.16.5.5

http://hints.macworld.com/article.php?story=2004062902195410


Solution 4:

I did this on Fedora by installing a local DNS server.

first install bind:

sudo dnf install bind

step 1: append a line to /etc/named.conf (as root):

include "/etc/named/freenode.net.conf";

step 2: create the zone file /etc/named/freenode.net.conf (as root):

zone "freenode.net" {
    type forward;
    forwarders { 8.8.8.8; };
};

now restart named:

sudo service named restart

now reconfigure your lan settings to use 127.0.0.1 as the DNS server, rather than the DCHP-allocated hosts.


Solution 5:

You can do it on Windows with PowerShell:

Add-DnsClientNrptRule -Namespace "pqr.com" -NameServers "10.0.0.1"

Reference: https://docs.microsoft.com/en-us/powershell/module/dnsclient/add-dnsclientnrptrule?view=win10-ps