Ubuntu – Global DNS change


How do I change my DNS server globally without having to do it manually through network manager for every connection I have.

I want to use OpenDNS, whether its at home, university, wifi hotspot, phone tether…

I use Ubuntu 13.10 but I guess it will be the same on newer versions.

Best Answer

You can add this file so network manager will update resolv.conf each time a connection is established:

echo "echo 'nameserver'>/etc/resolv.conf"> /etc/NetworkManager/dispatcher.d/10-FoeBud-dns
chmod +x /etc/NetworkManager/dispatcher.d/10-FoeBud-dns

(I would suggest the dns (FoeBud))


watch cat /etc/resolv.conf

Then restart networkmanager in another console with

service network-manager restart

... watch changing the resolv.conf file.


The local DNS caching on your machine by dnsmasq will not be available any more.

I also tried:

echo "nameserver">/etc/resolv.dnsmasq.conf
echo "resolv-file=/etc/resolv.dnsmasq.conf" > /etc/NetworkManager/dnsmasq.d/FoeBud-dns

which seemed somewhat cleaner or a shorter option would be:

echo "server=" > /etc/NetworkManager/dnsmasq.d/FoeBud-dns

But both options don't seem to work, because Network-Manager does start his own instance of dnsmasqwhich does not use those standard dnsmasq conf files.

A solution to this would be to detach dnsmasq from NetworkManager and install dnsmasq on its own (see https://superuser.com/a/809716/160420) but I personally don't want to change so much on my default Ubuntu system.