18

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
  • 23,120

7 Answers7

6

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.

Robie Basak
  • 15,670
4

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
belacqua
  • 23,120
4

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
Azendale
  • 11,891
  • 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 Oct 28 '12 at 20:30
  • Not working for me. The resolv.conf continues to get regenerated by wsl and overwrites the resolvconf settings. – Ya. Jan 28 '24 at 00:45
0

I resolved the same problem with the following commands:

echo "nameserver 212.217.0.1" >> /etc/resolvconf/resolv.conf.d/head
ln -s /etc/resolvconf/resolv.conf.d/head /etc/resolv.conf
resolvconf -u
/etc/init.d/networking restart
jokerdino
  • 41,320
moha
  • 9
  • 1
    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 Oct 28 '12 at 20:27
0

You could set the domain-name-servers dhclient.conf option.

Adam Byrtek
  • 9,811
-1

I had the exact same problem, the DNS server that my mobile provider provides was rather poor so I wanted to use Google's DNS. Also NetworkManager does a really poor job of handling mobile broadband connections so wvdial is a necessity.

As it turns out the /etc/resolv.conf is a symbolic link in ubuntu 12.10 and maybe even 12.04. Here's what I've done sudo unlink /etc/resolv.conf after this you can create a new resolv.conf with vim or the editor of your choice and add google's nameservers or any other nameservers that you prefer. Save it and you're done.

If you're afraid of breaking something you can make a note of the existing symlink by doing a ls -la /etc/resolv.conf before unlinking it.

Hope it helps.

nikhil
  • 1,472
  • @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 – nikhil Feb 08 '13 at 12:07
-1

you propably have the packet resolvconf installed. in that case, whenever an interface comes up, the resolv.conf is updated. you can add static entries using the /etc/resolv.conf.tail file, see the man page for resolv.conf for more.

eFloh
  • 99
  • noo i dont have that package installed – Jakh Saidlikp Mar 18 '11 at 21:11
  • 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.) – jdthood Oct 28 '12 at 20:35