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.

2
  • 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
    Mar 23, 2011 at 17:56
  • possible duplicate of DNS server configuration always be changed automatically
    – belacqua
    Mar 31, 2011 at 23:03

7 Answers 7

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.

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
6
  • @jgbelacqua i tried it in spearated lines but didnt work : P Mar 18, 2011 at 21:09
  • @Jakh I'm assuming that moving the prepend lines closer to the top also fails? (This is how I've got mine set up.)
    – belacqua
    Mar 18, 2011 at 22:02
  • @jgbelacqua yes i tried that too it does ;] Mar 18, 2011 at 22:13
  • @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?
    – belacqua
    Mar 18, 2011 at 22:18
  • @jgbelacqu No ill try it now and let you kno Mar 18, 2011 at 22:32
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
2
  • 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, 2012 at 20:30
  • Not working for me. The resolv.conf continues to get regenerated by wsl and overwrites the resolvconf settings.
    – Ya.
    Jan 28 at 0:45
0

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

3
  • check his pastebin -- looks like he already has this.
    – belacqua
    Mar 18, 2011 at 20:12
  • 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. Mar 18, 2011 at 20:14
  • hello @adam can youplease be more clear im a noob : ] thank Mar 18, 2011 at 21:30
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
1
  • 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, 2012 at 20:27
-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.

2
  • noo i dont have that package installed Mar 18, 2011 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, 2012 at 20:35
-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.

1
  • @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 8, 2013 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .