Find the answer to your Linux question:
Results 1 to 6 of 6
I have an annoying problem. Since I stopped using pppoe in Ubuntu and just used my existing router connection, some startup script or other keeps editing my resolv.conf so that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,218

    [SOLVED] Something keeps editing my resolv.conf file


    I have an annoying problem. Since I stopped using pppoe in Ubuntu and just used my existing router connection, some startup script or other keeps editing my resolv.conf so that the router is named as the nameserver. Result: my browser doesn't work. I have to copy back by hand the version of the file with the correct namesavers (which I keep saved under another name).

    As far as I can see, the only script which could be doing this is the dhclient script which I assume is run by ifup (eth0 is specified as dhcp). I tried changing /etc/network/interfaces to make eth0 static so that dhclient wouldn't run (I used the address and mask that my router normally allocates to it) but then it failed to come up at all.

    How do I stop this joker from messing up my configuration?
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  2. #2
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,134
    You can edit dhclient.conf to alter this behavior.

    Mine has

    Code:
    prepend domain-name-servers 127.0.0.1;
    because I run a caching nameserver on the local host.
    Prepend whatever server you want to appear at the
    top of /etc/resolv.conf

  3. #3
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,218
    I tried that but it makes no difference. I still ended up having to do it by hand.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,756
    When you are using DHCP, the default config is to let the DHCP script modify the resolv.conf with values received from the DHCP server.

    Where you disable/enable this varies by distro - I am sure Ubuntu's options are documented on Ubuntu's site or searchable on Google.

    Reading openSuSE's dhclient-script file, I can see that that settings are available in:

    /etc/sysconfig/network/config
    /etc/sysconfig/network/dhcp

    From /sbin/dhclient-script:

    Code:
    make_resolv_conf() {
      # first, look if we are allowed to modify resolv.conf:
      eval `grep "^MODIFY_RESOLV_CONF_DYNAMICALLY=" /etc/sysconfig/network/config`
      eval `grep "^DHCLIENT_MODIFY_RESOLV_CONF=" /etc/sysconfig/network/dhcp`
    
      test "$MODIFY_RESOLV_CONF_DYNAMICALLY" = no \
        -o "$DHCLIENT_MODIFY_RESOLV_CONF" = no \
        && return
    
      # It might be useful to have more than one domain in the searchlist. To
      # achieve this set DHCLIENT_KEEP_SEARCHLIST in /etc/sysconfig/network/dhcp to "yes"
      # and put the additional domains in the searchlist of the *unmodified*
      # /etc/resolv.conf. When the client is configured via DHCP the old
      # searchlist will be appended to the new one.
      oldsearchlist=""
      eval `grep "^DHCLIENT_KEEP_SEARCHLIST=" /etc/sysconfig/network/dhcp`
      if test "$DHCLIENT_KEEP_SEARCHLIST" = yes ; then
        oldsearchlist=`while read line; do 
                            case $line in search*) oldsearchlist=${line/search /};; esac; 
                    done< /etc/resolv.conf; 
                    echo -n $oldsearchlist`
      fi

  5. #5
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    edit /etc/resolv.conf so it has the right information, then
    Code:
    sudo chattr +i /etc/resolv.conf
    now the file is no longer able to be modified, even by root

  6. #6
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,218
    Quote Originally Posted by HROAdmin26 View Post
    When you are using DHCP, the default config is to let the DHCP script modify the resolv.conf with values received from the DHCP server.

    Where you disable/enable this varies by distro - I am sure Ubuntu's options are documented on Ubuntu's site or searchable on Google.
    Thanks, that's just what I needed. According to my dhcp man pages, the Ubuntu way to do it is to create a script in /etc/dhcp3/dhclient-enter-hooks.d that redefines the make_resolv_conf function (which the dhclient script uses to edit the resolv.conf file). So I redefined the function to run true and exit and now the file is no longer modified.

    The coopstahl3 solution is even simpler of course but it seems just a little bit like cheating!
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •