Fixing NetworkManager DNS issue in Ubuntu (Hardy Heron/Gutsy)
Using NetworkManager to change your DNS to custom servers, like OpenDNS, does not seem to stay between reboots. To fix this, edit the /etc/dhcp3/dhclient.conf file. In there, you will see a line similar to:
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, host-name,
netbios-name-servers, netbios-scope;
First of all, Remove domain-name-servers from that list.
Second, add a line to set your custom DNS servers. For OpenDNS, you would do:
prepend domain-name-servers 208.67.222.222,208.67.220.220;
Update: That doesn’t seem to always work. Easier way out would be to edit /etc/resolv.conf and add your DNS records like this:
nameserver 208.67.222.222
nameserver 208.67.220.220
Then run sudo chattr +i /etc/resolv.conf to stop NetworkManager from overwriting the file.
Your settings should now stay between restarts.


That didn’t work for me, because then the nm-applet takes forever trying to modify /etc/resolv.conf, and I never get a working Internet connection.
The solution is to edit /etc/dhcp3/dhclient.conf with the following line:
prepend domain-name-servers 208.67.222.222,208.67.220.220;
With the IP’s above you will be using the OpenDNS servers.
http://ubuntu.wordpress.com/2006/08/02/local-dns-cache-for-faster-browsing/
First solution did work for me. Tnx!
Thanks Mikhail
Your solution seems to be working fine for me as well.
Very Good Tip!!!
I tried both of these. Neither worked. I have used dhclient.conf to maintain my caching nameserver as the first entry in my resolv.conf file for years. Now, it really seems that NetworkManager has taken over stewardship of this file and does not provide a mechanism that replaces the old dhclient.conf prepend directive. This is a shame. They’ve missed the mark. Instead of making networking painless for me they’ve made it more painful.
Anyway, I decided that the easiest way out of this situation for me was to write this script which inserts localhost as the first name server regardless of who wants to own /etc/resolv.conf. (BTW, I used dnsmasq for DNS caching on my laptop)
% cat /etc/resolv.conf.fix
if [ ! -t 0 ]; then
exec > /dev/null 2>&1
fi
if ! grep -q 0.0.0.0 /etc/resolv.conf; then
ed /etc/resolv.conf << EOF
/^nameserver
i
nameserver 0.0.0.0
.
w
q
EOF
fi
Then, I added a cron entry in to root’s cron table to run this every minute.
I really didn’t like this solution but it was quick and dirty. It is not a good long-term solution. The best solution will be to fix NetworkManager to leave it alone or to allow prepending of nameservers into this file.
Overiding /etc/resolver.conf access rights really did it for me.
chmod -w /etc/resolver.conf
Tried this on Ubuntu 10.04, it works well! Thank you
My god!
this work VERY fine for me!
Thank you a lot.
i got an old laptop which runs version 8.04 (can’t install version 10 on it, yes, it’s that old :) )
changing /etc/resolv.conf messes up NetworkManager (results in a no working connection) but your first solution worked like a charm for me.
thanks a lot.
thanks man, helped
This works perfectly !!!!! thanks
thanks a lot
Very useful for fixing DNS on my Precise system. I prefer using dnscache, so really hate NM taking over DNS.
From various tries, I have reached this conclusion:
1. NetworkManager (NM) doesn’t care about any DNS case configuration in “/etc/dhcp/dhclient.conf” as long as “/etc/NetworkManager/NetworkManager.conf” has “dns=dnsmasq”.
2. Once you comment that out in “/etc/NetworkManager/NetworkManager.conf” and restart NM, then the behaviour of the system reverts to that before all this NM/dnsmasq crap. In other words, you don’t need to remove “request domain-name-servers” from “/etc/dhcp/dhclient.conf” , and “prepend domain-name-servers” works. Together, just like you want, you get your custom DNS server before the DHCP supplied ones.
I am happy, thanks!
[…] additional look at this post by Mikhail Esteves with some trial and error, got me an easy […]