I (think) that I've configured a static IP address in /etc/network/interfaces:

# The primary network interface 
auto eth0 
iface eth0 inet static

And I change the file /etc/resolv.conf to include the desired nameservers.

Then I restart networking sudo /etc/init.d/networking restart

But after some hours resolv.conf always reverts back to the DHCP nameserver.

I should also say that this is Ubuntu Server with only l0 and eth0 interfaces.

  • Is the resolvconf package installed? Sep 26 '11 at 23:14
  • Are you trying to use dhclient on another network interface (maybe a wifi or dial up interface), or is dhclient incorrectly running on eth0 even though it's supposed to be static?
    – poolie
    Sep 26 '11 at 23:34
  • There is only eth0 and lo0, the IP I manually set is the same as the DHCP IP I will get (the DHCP server will always serve the same static IP). But I don't want to use the nameserver given by the DHCP server, so I thought I would set the IP myself and there would not be any DHCP, but I don't understand why the resolv.conf keeps being updated. Sep 26 '11 at 23:54
  • Gilles - no, I ran: dpkg -L resolvconf, and get: Package `resolvconf' is not installed. Sep 26 '11 at 23:56

If you want to override or append to the name servers suggested by the DHCP server, you can configure this in /etc/dhcp/dhclient.conf, eg:

interface "eth0" {
    prepend domain-name-servers;

You can also do this from the "Edit Connections" control in the network indicator in Unity or GNOME.

  • 5
    This was the best solution, I posted another option, but realized that setting a static IP was not a good idea in an AWS EC2 environment. :) Sep 28 '11 at 20:09
  • What if you want to prepend several domain name servers?
    – blueFast
    Mar 14 '18 at 6:45
  • Prepending domain name server seems to discard the name server supplied by dhcp (this does not happen prepending other name servers)
    – blueFast
    Mar 14 '18 at 6:45
  • 3
    Replace prepend with supersede to overwrite DHCP value completely.
    – Sqerstet
    Feb 16 '19 at 18:23
  • 1
    @ctrl-alt-delor yes, you can just put the prepend or supersede at the top level, with no interface block
    – poolie
    Mar 31 '20 at 0:36

A resolution that will resolve your problem is to configure your resolvconf package. This will give precedence to your preferred nameservers as well as any other desired settings resolv.conf settings such as search and domain preferences.

Edit the file: /etc/resolvconf/resolv.conf.d/head

Place your desired nameservers and any other configurations you want to take preference when there is a network change there. When any changes to the network happen, the configuration there will always take precedence.

An example of the /etc/resolvconf/resolv.conf.d/head file:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

search mydomain.com

Look at the answer to a similar question:
override dns nameserver

Be sure to have a linefeed after the last entry. Most editors will provide a linefeed automatically when saving the file.


I found a reference to removing the dhcp client, I think that was the main culprit. I've done this and haven't seen the problem yet. Will wait 'till morning to confirm, but it appears that the dhcp client was still running and had to be stopped and uninstalled.

apt-get remove isc-dhcp-client dhcp3-client dhcpcd
  • I'm slightly confused if the solution was the prepend command or if it was actually removing the DHCP client. Mar 27 '12 at 8:24
  • @EugenevanderMerwe It's the prepend command. The poster said "This was the best solution, I posted another option, but realized that setting a static IP was not a good idea in an AWS EC2 environment. :) " Jan 22 '16 at 21:38

As a rule of thumb, you should always uninstall all network services using apt-get --purge remove <package-name>. In this way, all configuration files will be removed as well.

In this case the command would be:

apt-get --purge remove isc-dhcp-client isc-dhcp-common

This command will completely remove the isc-dhcp-client.

  • 4
    How is this relevant, and why do you think it's a good general rule? He doesn't want to stop using DHCP?
    – poolie
    Oct 11 '13 at 22:22

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.