Subject: Re: dhclient erases(!?) /etc/resolv.conf (fwd)
To: Mipam <mipam@ibb.net>
From: Richard Rauch <rauch@rice.edu>
List: netbsd-help
Date: 04/01/2002 19:42:01
> > I decided to try running dhclient on my laptop in a different environment
> > today.  I was disturbed to discover that dhclient appears to have
> > oblitterated my old /etc/resolv.conf (rather blindly), and did not restore
 [...]
> > Is this an intended feature, or was it just that no one considered that
 [...]
> Well, i guess it's intended.
> In /sbin/dhclient-script (or /etc/....):
 [...]

Yes, it does seem that the script is oblitterating the old file.

The question is: Is this a matter of oversight, or is there some good
reason to erase (without warning, etc.) your static configuration?

It appears that dhclient-script's EXITHOOKS/ENTERHOOKS handling will let
me install hooks to preserve my static configuration.  I think that
something along these lines should be done in the default DHCP behavior.
That, or dhclient[-script] should document the destruction of static data
in the BUGS section.  (dhclient-script documents a related situation with
resolv.conf, with regard to running multiple dhclients on one machine.
But that's not really considered to be a bug, and indeed apparently causes
no harm in that case.)

My outlined solution:

 * *Mark* DHCP-generated files (where possible).  E.g., resolv.conf
   should have a ``# automatically generated by dhclient-script'' at
   the top, or similar.  (I'm not sure what other files might be
   created by DHCP, now or in the future.  Take this as a general
   comment.  (^&)

 * For resolv.conf in particular, on entry to dhclient-script:

     if $RESOLV exists and isn't DHCP-generated
       mv $RESOLV $RESOLV.static

 * For resolv.conf in particular, on exit_with_hooks in dhclient-script:

     if $RESOLV.static exists
       mv $RESOLV.static $RESOLV
     else if $RESOLV exists and is DHCP-generated
       rm $RESOLV

...this should preserve static configuration data, even if multiple
dhclients are run, or dhclient-script otherwise gets (bogus?) multiple
entry/exit events.  (The only problem may be if one runs two dhclients,
then removes one with ``dhclient -r''.  I don't know what the present
system does in such a case, so my suggestion might break that situation.)


(The explicit DHCP-generated marks seem to be the simplest and
cleanest---and I think most reliable---way to determine the difference
between static and dynamic configuration data.  Besides, it's nice to let
a human peruser of a file know where the file came from.  (^&)


  ``I probably don't know what I'm talking about.'' --rauch@math.rice.edu