0

I am trying to have my eth1 use 10.50.1.11 and 10.50.1.12 dns servers whilst my eth0 interface uses 8.8.8.8 and 8.8.4.4 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?

  • 3
    DNS does not work as you think it works. It is global to the system, not based on interface. – Rui F Ribeiro Mar 5 at 17:31
  • 1
    This sounds like an XY problem. Consider asking a separate question where you explain what exactly is the end result that you want to achieve. This general question is still perfectly valid and interesting for people wondering how DNS resolution works. – TooTea Mar 5 at 18:05
  • 1
    You can use network namespaces, put eth0 and eth1 into different namespaces (or one in the main namespace, one in a new namespace). Network namespace allows different versions of resolv.conf in /etc/netns/<namespace_name>/resolv.conf, at least for sufficiently modern applications that pay attention to that. – dirkt Mar 6 at 11:08
1

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 getaddrinfo or 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.