Red Hat Bugzilla – Bug 11347
ifup and ifdown should update /etc/resolv.conf
Last modified: 2014-03-16 22:13:47 EDT
Feature request: it'd bw nice to be possible to define a set of DNS
servers per interface, e.g. eth0 should know about its
own /etc/resolv.conf, ppp0 should have its own set of /etc/resolv.conf
associated to it, ppp1, etc.
This is useful when switching between connections a lot,
the /etc/resolv.conf file should get updated (it does get updated now when
switching eth -> ppp connection, but when coming back to eth0 it does not
get reverted back).
I would have it so that when you call 'ifdown <device>' take out just the
entries from /etc/resolv.conf for that <device>, when calling 'ifup
<device> merge into /etc/resolv.conf the entries for <device>. A simple
file replacement policy would be acceptable, too.
I had to write some wrapper scripts that replace /etc/resolv.conf, it
would be nice if I did not have to maintain them myself :-) but instead
make them part of the release.
Removing entries for which there is no route would be easy, but adding them back
in would be difficult. The kernel will already give a process an error if there
is no route to a particular IP being tried, so most of the time this is only
an issue if you're running a caching nameserver with a network connection that
is down for non-trivial amounts of time.
Is there a reason this can't be done on your system with a local script named
"/sbin/ifup-local"? (The ifup commands will run that script if it exists.)
I'm not sure I understand how ifup-local would work, would that get called from
ifup if the script exists? This feature needs to be added in a future release,
it is not there yet, right? What would the ifup-local script do in that case?
Just replace /etc/resolv.conf with the appropriate one?
The logic to call /sbin/ifup-local has been in the initscripts package for some
time now. It is called from ifup-post (in /etc/sysconfig/network-scripts) with
the network device name ("ppp0") as its sole argument. Similary, a script named
/sbin/ifdown-post would be called when an interface is taken down.
I think something like "cat /etc/resolv.conf.$1 >> /etc/resolv.conf" would do
what you're looking for in an ifup-local, and a corresponding
"fgrep -vf resolv.conf.eth0 /etc/resolv.conf > /etc/resolv.conf.$$ && \
mv /etc/resolv.conf.$$ /etc/resolv.conf" in ifdown-local would undo it.
Thanks, that should do it.