Note: This article is outdated as of Ubuntu 12.04. Please see this article if you're using Ubuntu 12.04 or later.
Dynamic Host Configuration Protocol (DHCP) is a commonly used method of obtaining IP and DNS information automatically from the network. In some cases, you may wish to statically define the DNS servers instead of using the ones provided by the DHCP server. For example if your ISP commonly experiences DNS outages, you might want to use the DNS servers provided by OpenDNS instead of the ones provided by your ISP.
When using a static IP configuration on Linux, you normally add the DNS servers to the
/etc/resolv.conf. However, if you try to add a DNS server to
/etc/resolv.conf under a DHCP configuration, you'll notice that your static entry disappears as soon as the DHCP client runs (usually on boot). To prevent this, you need to tell the DHCP client to prepend the static DNS server(s) to
/etc/resolv.conf before adding the ones provided from the DHCP server (if any).
The configuration file you'll need to edit is the same on both Debian and Ubuntu, however depending on your setup the location of the file may vary. Here are the two common places I've found the file:
Open the file in your favorite editor and add one of two lines at the top, separating multiple DNS servers with a comma and ending the entry with a semi-colon:
If you simply want to add static DNS servers to be used in addition to the ones provided by DHCP, use a prepend entry:
prepend domain-name-servers 18.104.22.168, 22.214.171.124;
If you want to override the DNS servers provided by DHCP entirely and force the system to use the ones you provide, use the supersede entry:
supersede domain-name-servers 126.96.36.199, 188.8.131.52;
Before these static DNS servers will to be appended to your
/etc/resolv.conf file, you'll need to re-run the DHCP client. The easiest way to do this is by running
/etc/init.d/networking restart (sudo required) or you can try running the
After re-running the DHCP client, check your
/etc/resolv.conf file to confirm the static DNS servers have been added.