I am trying statically to set DNS server addresses in my Ubuntu server running as virtual machine. I followed all recommendations on official Ubuntu support pages but I simply cannot get rid of my ISP's DNS servers set by DHCP.

I assigned br0 interface on my host machine static IP address and eth0 on VM to use Google DNS and my own local DNS running on the second vm by setting it in /etc/network/interfaces. Tried to fiddle with head base and tail files in /etc/resolvconf/resolv.conf.d/ and tried to shuffle interface-order in /etc/resolvconf/interface-order but when I restarted network service I got the ISP's DNS addresses back every time.

Is there a way that I can disable resolvconf and set up my resolv.conf file manually as I always did on Red Hat? Or at can you tell me which hook script keeps putting ISP DNSs in resolv.conf? My ISP don't allow me to change DHCP settings on my router so I cannot do it that way.

Why is such a simple thing such as setting DNS servers got so complicated???


1: Resolvconf writes its dynamic resolv.conf file at /run/resolvconf/resolv.conf. /etc/resolv.conf is a symbolic link to the latter location. If you want to use a static resolv.conf file, simply replace the /etc/resolv.conf symbolic link with a file. This is currently supported but not recommended.

2: As I understand it, the affected machine is running Ubuntu Server edition. In that case it configures interfaces using the ifup program whose configuration file is /etc/network/interfaces. For interfaces configured via the dhcp method, ifup (normally) uses dhclient from the isc-dhcp-client package. Dhclient receives nameserver information from the DHCP server and its hook script /etc/dhcp/dhclient-enter-hooks.d/resolvconf sends this information to resolvconf which puts it into resolv.conf.

One thing you can do is edit /etc/resolvconf/interface-order such that eth0.dhcp comes before eth0.dhclient. (I assume that the relevant interface is eth0.) If you have the default interface-order you can, for example, just add a line eth0.dhcp before the line eth*.

--- interface-order_ORIG    2012-11-06 10:12:47.630529145 +0100
+++ interface-order 2012-11-06 10:13:16.410529800 +0100
@@ -9,6 +9,7 @@

Then add a dns-nameservers line to the iface eth0 stanza in /etc/network/interfaces with the correct nameserver address.

iface eth0 inet dhcp

Because eth0.dhcp comes before eth0.dhclient, the correct nameserver address will be included in resolv.conf before the incorrect one.

Another way to override the unwanted behavior of including the DHCP-server-provided nameserver address is to edit the dhclient hook script. E.g., you can add a line like the following (where is a nameserver address you would like to discard).

--- resolvconf_ORIG 2012-03-29 22:37:14.000000000 +0200
+++ resolvconf  2012-11-05 20:53:33.312681077 +0100
@@ -54,6 +54,7 @@
            shopt -s nocasematch
            for nameserver in $new_dhcp6_name_servers ; do
+               [ "$nameserver" = "" ] && continue

Yet another possibility (a slightly crude one, since it's completely static) is to add a nameserver option to /etc/resolvconf/resolv.conf.d/head.

3: Setting DNS nameserver addresses has gotten more complicated because machines are becoming mobile, are getting more and more interfaces and static configuration is gradually being replaced by autoconfiguration.

| improve this answer | |
  • +1 for deleting the symlink and uninstalling resolvconf! – ColinM May 8 '13 at 21:22
  • 2
    Even if you want a completely static /etc/resolv.conf and delete the symlink there, you still shouldn't uninstall resolvconf because its mere presence causes other programs to refrain from overwriting /etc/resolv.conf. – jdthood May 9 '13 at 21:21

Simply leverage dhclient (this uses google DNS for example purposes). This is much cleaner than the other answers IMO:

  1. Back up /etc/resolv.conf: sudo cp /etc/resolv.conf /etc/resolv.conf.auto

  2. Edit /etc/dhcp[3]/dhclient.conf (ubuntu 14.04 omits the 3): sudo vi /etc/dhcp/dhclient.conf

  3. If there is a line containing domain-name-servers, write down the IP addresses for future reference.
  4. Replace that line with, or add, the following line: For IPv4: prepend domain-name-servers,; For IPv6: prepend domain-name-servers 2001:4860:4860::8888, 2001:4860:4860::8844;
  5. Now release and renew IP: ifdown eth0 && ifup eth0

Now restart any network clients you are using (like chrome or whatnot)

| improve this answer | |

IMO: this is a bug in the graphical configuration tool.

My easiest fix is to comment (or remove) the line starting with "request..." in file /etc/dhcp/dhclient.conf

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.