All pastes #474821 Raw Edit

resolv.conf

public text v1 · immutable
·published 2007-05-07 00:58 UTC
rendered paste body
Goal:

I need a way to change the add_new_resolv_conf function in the dhclient-script such that the resolv.conf file is actually created in a different location than standard /etc/resolv.conf.

Reason:

On my FreeBSD router box I want to run dnsmasq to serve as a simple dhcp and dns caching server and dnsmasq can be authoritative for my internal NON-public domain name.

The router itself needs to have a /etc/resolv.conf file that points to itself as the name server, but dnsmasq needs a resolv.conf file that points to a real (as in ISP provided) name server.  The dnsmasq program can be configured to get its resolv.conf information from a different file OTHER than the default /etc/resolv.conf say /etc/resolv.conf.dnsmasq.

I need a way to have the dhclient-script create the /etc/resolv.conf file in the OTHER location so dnsmasq can use it and so that the sytems /etc/resolv.conf can be left untouched.  

History:

Several resources suggested creating a dhclient-enter-hooks file with the following contents:

make_resolv_conf() {
echo “Doing nothing to /etc/resolv.conf.”
}

Problem1:

This solution doesn’t work at all on FreeBSD as the FreeBSD default dhclient-script calls its function to make the resolv.conf file “add_new_resolv_conf”.

So if you edit the dhclient-enter-hooks file and change the function name to match what is in the FreeBSD dhclient-script then you have something like this:

add_new_resolv_conf() {
echo “Doing nothing to /etc/resolv.conf.”
}

Which gets me closer to where I want to be, but not quite.

Problem2:

the “solution” in Problem1 is inadequate at least and problematic and buggy at worst.

Having two functions in a single script defined by the same name is bad programming form, and prone to bugs as the system must decide which function to execute if any.

In my tests NEITHER function was executed.

I can’t reliably depend on NEITHER function being executed and keeping my system running the way I want it to.

Proposed Solution:

Create a dhclient-enter-hooks like this:

alternate_resolv_conf_funtion=”new_make_resolv_conf”

new_make_resolv_conf() {
echo “Doing nothing to /etc/resolv.conf”
}

<Authors note:>
  If I can get this to work, I can make the function do what I want, yes I know this function doesn’t exactly go with my goal statement.  I’m not putting the full substitute function in this writeup for brevity, I’m just trying to illustrate the concept.
<End Note>

Now in the dhclient script where the call to the current add_new_resolv_conf in made do something like this:

if  [ -n “$alternate_resolv_conf_function” ] //test if alternate function request as been made
then
$alternate_resolv_conf_function //if it has call it
else
add_new_resolv_conf // if it hasn’t call the standard function.
fi

The way I see things this almost works, but I am left with the following two questions:

Question 1:

Can you really call a function this way?  I’ve never tried this before in a simple bash script, so I’d don’t even know if this is possible.

Question2:  Since the goal is to save the /etc/resolv.conf file in a “new location” then there may be other places in the dhclient-script that could potentially undo what I’ve tried to fix.  As I look through the code in the dhclient-script file, I do see that there are other places where /etc/resolv.conf is potentially created.

This makes me wonder about the validity of the whole approach.

What about maybe defining the name of the /etc/resolv.conf file in the dhclient-enter-hooks script?

Something like alternate_resolv_conf_name=”/etc/resolv.conf.dnsmasq”

then similarly adjusted if statements in the dhclient-script?