I am trying to have my eth1 use 10.50.1.11 and 10.50.1.12 dns servers whilst my eth0 interface uses 188.8.131.52 and 184.108.40.206 dns servers. I am running centos 7 vms within xenserver 6.5. eth1 is a closed-circuit vlan, whilst eth0 is the public network. The problem im having is that my centos client automatically picks which dns server it uses based upon which interface comes up first. I know that when you define dns servers in /etc/network-scripts/ifcfg-eth0 or /etc/network-scripts/ifcfg-eth1, it prints it out inside of /etc/resolv.conf, but i cant find a workaround for this. Does anyone know if you can assign different DNS servers to different network interfaces?
No, that simply can't be done due to the way address resolution works.
When a process on the machine wants to connect to, say, example.com, it first calls a library routine like
gethostbyname. The purpose of these routines is to translate the DNS name to an IP address. So they look into
/etc/resolv.conf, read the IP address of a DNS server, send a DNS query packet to that server, receive the reply and return the resulting IP address to the caller.
At that point, the process takes the resolved IP address and passes it to a system call such as
connect. This is where the kernel steps in, looks into its routing table and figures out which interface to use to connect to that address.
So in short, DNS settings simply cannot depend on the interface used for communication, because the choice of that interface itself depends on the DNS settings.