Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would you configure a DNS Name Server per NIC (eth0 vs eth1) interface on RHEL/Centos 6?


eth0 is on subnet

eth1 is on subnet

Any requests sent over eth0 should use DNS server

Any requests sent over eth1 should use DNS server

I've added:

DNS1: > /etc/sysconfig/network-scripts/ifcfg-eth0

DNS1: > /etc/sysconfig/network-scripts/ifcfg-eth1

However these values get ignored, and it always defaults to the setting in resolv.conf "nameserver" When eth0 is down, connections are sent over eth1 ... however DNS can no longer resolve as it's trying to reach

  • How do I get it to respect the DNS settings in ifcfg rather than a default for resolv.conf?

  • Or how do I configure a different DNS Name Server for eth0 vs eth1?

  • Is there a better way of handling this?


We have two VLANS, each has it's own DNS server on it's respective subnet. These handle look-ups for local DNS (example.loc, etc), as well as forwarding when needed.

These are two separate servers in two separate physical locations. If possible I'd rather not run one server across the two subnets (one handles sensitive data).

If eth0 was to go down, I need eth1 to continue to be able to make DNS requests.

I thought about adding two IPs to resolv.conf, and then letting it fallover if it can't reach the server in the first subnet, but this seems inelegant (having to wait for the first server to timeout with every DNS query when eth0 is down).

share|improve this question
What about setting nameserver and nameserver in resolv.conf? – InternetSeriousBusiness Sep 3 '12 at 14:16
If one subnet handles sensitive data as you say, what business does this particular machine have being connected to both subnets? – Ansgar Wiechers Sep 3 '12 at 19:30
up vote 5 down vote accepted

You can't easily do what you want.

Or how do I configure a different DNS Name Server for eth0 vs eth1?

The name lookup for a hostname happens through standard system libraries and isn't associated in any way with a particular "connection". In fact, at the time the DNS query happens, there is no connection, because your application hasn't even figured out the address to which it's going to connect (which is why it's using DNS in the first place).

How do I get it to respect the DNS settings in ifcfg rather than a default for resolv.conf?

The Linux resolver only has a single, global configuration (/etc/resolv.conf). There is no per-interface, per-domain, or per-connection setting of any sort. The settings in /etc/sysconfig/network-scripts/... are only used to populate /etc/resolv.conf, and generally if you specify DNS1 and DNS2 in these files, the last interface to come up will be what you see in /etc/resolv.conf.

Is there a better way of handling this?

Can you tell us what you're actually trying to accomplish? We might be able to suggest better solutions if you can tell us more about your specific situation.

share|improve this answer
Updated with some further information. Thank you. – DevGav Sep 3 '12 at 16:11
Have decided for now just to edit /etc/resolv.conf, and shorten the timeout. Thank you for your help. – DevGav Sep 4 '12 at 19:44
what's confusing to me is that even though DNS is not associated with a particular interface because there's as yet no connection, nevertheless DNS servers must be specified at the interface level. seems arbitrary :/ – RubyTuesdayDONO Jun 17 at 21:46

A DNS request is basically either

  1. "what's the IP address of," or
  2. "what's the hostname of"

So there's no knowing at "request" time which Ethernet card is going to be involved. What you could reasonably ask would be "all requests ending in '' should go to, and all other requests should go to"

And likewise, "All reverse DNS requests matching should go to, and the rest should go to"

As larsks said, Linux doesn't support such a configuration. However, you could run your own, minimal DNS server that implements the above logic, and forwards requests to the appropriate "real" DNS server.

I believe dnsmasq can do this (see How to configure dnsmasq to forward multiple DNS servers?). But before I found that out, I rolled my own in Twisted:

from twisted.internet import reactor
from twisted.names import dns
from twisted.names import client, server

class Resolver(client.Resolver):
  def queryUDP(self, queries, timeout=None):
    if len(queries) > 0 and (str(queries[0].name).endswith(''):
      self.servers = [('', 53)]
      self.servers = [('', 53)]
    return client.Resolver.queryUDP(self, queries, timeout)

resolver = Resolver(servers=[('10.0', 53)])
factory = server.DNSServerFactory(clients=[resolver])
protocol = dns.DNSDatagramProtocol(factory)

reactor.listenUDP(53, protocol, interface='')
reactor.listenTCP(53, factory, interface='')
share|improve this answer

Your Answer


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.