Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Networking > [SOLVED] Something keeps editing my resolv.conf file

Forgot Password?
 Linux Networking   Hardware/Software related, Modems, Internet connection sharing, IPTables etc.

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Closed Thread
 
Thread Tools Display Modes
Old 07-28-2008   #1 (permalink)
Linux User
 
hazel's Avatar
 
Join Date: May 2004
Location: Harrow, UK
Posts: 481
[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!"
hazel is offline  


Old 07-28-2008   #2 (permalink)
Linux Enthusiast
 
rcgreen's Avatar
 
Join Date: May 2006
Location: the hills
Posts: 708
Send a message via Yahoo to rcgreen
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
rcgreen is offline  
Old 07-30-2008   #3 (permalink)
Linux User
 
hazel's Avatar
 
Join Date: May 2004
Location: Harrow, UK
Posts: 481
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!"
hazel is offline  
Old 07-30-2008   #4 (permalink)
Linux Engineer
 
Join Date: Nov 2007
Posts: 1,120
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
HROAdmin26 is offline  
Old 07-30-2008   #5 (permalink)
Linux Guru
 
coopstah13's Avatar
 
Join Date: Nov 2007
Location: NH, USA
Posts: 1,693
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
coopstah13 is offline  
Old 07-31-2008   #6 (permalink)
Linux User
 
hazel's Avatar
 
Join Date: May 2004
Location: Harrow, UK
Posts: 481
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!"
hazel is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 11:57 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2