On Sat, 8 Mar 2003, IAccounts wrote:

> > > Alternatively is there a way to dynamically tell BIND to get it's
> > > forwarders list from /etc/resolv.conf?

Here is a shell script snippet that I use on my laptop.  It gets
called from make_resolv_conf() in /etc/dhclient-enter-hooks, where I
make sure not to overwrite /etc/resolv.conf (it always points to
localhost).  Extracting nameserver addresses from resolv.conf is
trivial, though.

A prerequisite is that the "forwarders" clause in named.conf is on a
single line by itself, for example:

  forwarders { 192.168.250.254; };

----8<------------------------------------------------------------
LOGGER=echo
named_conf=/etc/namedb/named.conf

# Args: one or more nameserver IPs
update_forwarders() {
    address_list=
    for nameserver in $* ; do
        test X$nameserver = X127.0.0.1 && continue  # Stupid server...
        address_list="$address_list $nameserver;"
    done
    address_list="{ $address_list };"
    sed_command='/^options/,/^}/s/\([^#\/]*\)forwarders.*/\1forwarders'
    sed_command="$sed_command $address_list/"
    sed "$sed_command" $named_conf > $named_conf.dhcp
    if cmp -s $named_conf $named_conf.dhcp; then :
    else
        $LOGGER "New DNS servers: $*"
        if [ ! -f $named_conf.org ]; then
            cp $named_conf $named_conf.org
        fi
        cp $named_conf.dhcp $named_conf
        ndc reload
    fi
    return 0
}
----8<------------------------------------------------------------

It is more elegant in perl, but dhclient-enter-hooks is a shellscript,
so it felt easier to just add it there.

  $.02,
  /Mikko


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message

Reply via email to