Why does my resolv.conf file get regenerated every time?

20,719

Solution 1

In 12.04, resolvconf is installed by default. Here is a quick summary of how to make DNS configuration changes for some common use cases:

For a static configuration using ifup, use dns-nameservers and dns-search entries in /etc/network/interfaces.

For a static configuration using NetworkManager, select the Automatic (DHCP) addresses only Method and enter addresses and domain names in the Additional DNS servers and Additional search domains fields in the Connection Editor.

To override resolvconf's default configuration, use base, head and tail in /etc/resolvconf/resolv.conf.d/. Only enter addresses and domain names in these files as a temporary measure, since they really belong elsewhere, as described above.

Disabling resolvconf is not recommended, but you can replace the symlink /etc/resolv.conf with a regular file.

For more information, see Stéphane Graber's blog post.

Solution 2

The best way to set a nameserver via the CLI, without NetworkManger, with a static address, or independent of the connection is this:

Install the resolvconf package.

Run

sudo nano /etc/resolvconf/resolv.conf.d/head

(ignore the scary warning. /etc/resolv.conf is autogenerated, so the warning is there so it will get put in /etc/resolv.conf when /etc/resolv.conf is generated.) To the end of the file, add

 nameserver <ip_of_nameserver>

Press Ctrl x and answer yes to saving the file. To finish up, regenerate /etc/resolv.conf so the changes are applied right now:

 sudo resolvconf -u

Solution 3

If all you want to do is to keep your Google DNS servers in resolv.conf, you can edit
/etc/dhcp3/dhclient.conf and add :

prepend domain-name-servers 8.8.8.8;
prepend domain-name-servers 8.8.4.4;

The only difference between what you have and what I'm showing here is that you've got both name-servers on a single line, per the docs you've mentioned.

Unless I'm missing something, your dhclient.conf is not a problem here. At this point, I'm assuming that the issue has to do with wvdial.

Here's something to try, from ubuntuforums:

gksudo gedit /etc/ppp/peers/wvdial

REMOVE parameter usepeerdns and save file. Code:

gksudo gedit /etc/wvdial.conf

add these lines:

check DNS = no
auto DNS = no
Share:
20,719

Related videos on Youtube

ASBai
Author by

ASBai

Updated on September 17, 2022

Comments

  • ASBai
    ASBai over 1 year

    My /etc/resolv.conf file gets regenerated every time, making me loose Google DNS servers when I reconnect my 3G modem.

    For changing the DNS settings, I looked at http://code.google.com/intl/fr-FR/speed/public-dns/docs/using.html.

    My dhclient.conf is pretty big (58 lines), so I posted it on pastebin.

    However, here is the entire dhclient.conf without comment lines or blank lines:

    option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
    send host-name "<hostname>";
    request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;
    prepend domain-name-servers 8.8.8.8, 8.8.4.4;
    

    I am using wvdial instead of Network Manager.

    • belacqua
      belacqua about 13 years
      Unfortunately, I know nothing about wvdial . At this point I suspect it or another package not yet discovered is involved here. Do you know if you've installed other network-related applications or tools that might be touching DNS, DHCP, interfaces, etc. in some fashion?
    • belacqua
      belacqua about 13 years
  • belacqua
    belacqua about 13 years
    check his pastebin -- looks like he already has this.
  • cokeman19
    cokeman19 about 13 years
    Thanks, I didn't notice that. By the way, your solution could be correct, so consider posting it as an answer instead of a comment.
  • ASBai
    ASBai about 13 years
    @jgbelacqua i tried it in spearated lines but didnt work : P
  • ASBai
    ASBai about 13 years
    noo i dont have that package installed
  • ASBai
    ASBai about 13 years
    hello @adam can youplease be more clear im a noob : ] thank
  • belacqua
    belacqua about 13 years
    @Jakh I'm assuming that moving the prepend lines closer to the top also fails? (This is how I've got mine set up.)
  • ASBai
    ASBai about 13 years
    @jgbelacqua yes i tried that too it does ;]
  • belacqua
    belacqua about 13 years
    @Jakh -- have you tried editing the request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, domain-search, host-name, netbios-name-servers, netbios-scope, interface-mtu, rfc3442-classless-static-routes, ntp-servers; line to remove name-servers there?
  • ASBai
    ASBai about 13 years
    @jgbelacqu No ill try it now and let you kno
  • ASBai
    ASBai about 13 years
    @jgbelacqu No its didnt work : [
  • jdthood
    jdthood over 11 years
    You may have resolved the problem this way, but it is an utter misconfiguration. You have ended up symlinking /etc/resolv.conf to a static file which happens to be one of resolvconf's configuration files. If you want to disable resolvconf then it would be much simpler just to delete the symlink /etc/resolv.conf and put a static file there.
  • jdthood
    jdthood over 11 years
    It should be added that it is generally not a good idea to put a static nameserver address in resolv.conf. Please read /usr/share/doc/resolvconf/README.gz.
  • jdthood
    jdthood over 11 years
    The resolvconf program updates /etc/resolv.conf, but only if /etc/resolv.conf is a symbolic link to ../run/resolvconf/resolv.conf. The resolvconf package was introduced because so many other programs were stomping on /etc/resolv.conf independently of one another, resulting in chaos. Please read /usr/share/doc/resolvconf/README.gz. Thus from the fact that /etc/resolv.conf was updated, it does not follow (in March 2011 when the question was asked) that resolvconf was installed. More probably pppd was rewriting the file. (As of Ubuntu 12.04, however, resolvconf is part of the base system.)
  • nikhil
    nikhil about 11 years
    @Downvoter, care to comment. If my answer is really bad advice I'll be happy to delete it. Please do let me know what I'm doing wrong. Thanks