/etc/resolv.conf getting over written with dhcp

Ian Lepore freebsd at damnhippie.dyndns.org
Wed Jun 27 22:20:25 UTC 2012


On Wed, 2012-06-20 at 13:39 +0530, Varuna wrote:
> Ian Lepore wrote:
> > 
> > Using the 'prepend' or 'supercede' keywords in /etc/dhclient.conf is
> > pretty much the standard way of handling a mix of static and dhcp
> > interfaces where the static config needs to take precedence.  I'm not
> > sure why you dismiss it as essentially good, but somehow not good
> > enough.  It's been working for me for years.
> > 
> > -- Ian
> > 
> The issue that I had indicated that the issue with the /etc/resolv.conf is being 
> caused by an error in /sbin/dhclient-script; hence, I am definitely not looking 
> at solving the issue either with /etc/dhclient.conf or /etc/dhclient-exit-hooks 
> configuration file.
> 
> BTW, resolver(5) / resolv.conf(5) does not mention the usage of 
> /etc/dhclient-exit-hooks file to protect the earlier contents of 
> /etc/resolv.conf file.  Will put this issue in the freebsd-doc mailing list.
> 
> With regards,
> Varuna
> Eudaemonic Systems
> Simple, Specific & Insightful

I have re-read your original message and I think the confusion is here:


> 2***            # When resolv.conf is not changed actually, we don't
>                  # need to update it.
>                  # If /usr is not mounted yet, we cannot use cmp, then
>                  # the following test fails.  In such case, we simply
>                  # ignore an error and do update resolv.conf.
> 3***            if cmp -s $tmpres /etc/resolv.conf; then
>                          rm -f $tmpres
>                          return 0
>                  fi 2>/dev/null
> [...]
> I guess, the 1***, 3*** and 4*** is causing the recreation of /etc/resolv.conf. 
>   Is this correct? I did a small modification to 3*** which is:
>                  if !(cmp -s $tmpres /etc/resolv.conf); then
>                          rm -f $tmpres
>                          return 0
>                  fi 2>/dev/null
> This seems to have solved the issue of /etc/resolv.conf getting overwritten with 
> just: nameserver 192.168.98.4.  This ensures that: If there is a difference 
> between $tmpres and /etc/resolv.conf, then it exits post removal of $tmpres.  If 
> the execution of 3*** returns a 0, a new file gets created.  I guess the 
> modification get the intent of 3*** working.
> 
> Have I barked up the wrong tree?

I think yes, you have barked up the wrong tree.  The intent of the code
at 3*** is not to exit if there is a difference, it is to exit if there
is NO difference.  In other words, if the old and new files are
identical then there is no need to re-write the file, just cleanup and
exit.  If the files are different then replace the existing file with
the new one.

This is just the (sometimes annoying) way dhcp works.  If the dhcp
server provides new resolver info it completely replaces any existing
resolver info unless you've configured your dhclient.conf to prevent it.
It only does so if the interface being configured is the current
default-route interface, or there is no current default-route interface.

-- Ian




More information about the freebsd-hackers mailing list