Static DNS with DHCP in Ubuntu

If you've ever found yourself in the position where you DHCP within a network, but want to use different DNS servers than the default network DNS servers, this tip might be for you. With Ubuntu in roaming mode, it will grab the first DHCP server it can find and the default DNS server for that network. Regardless of what DNS servers you list in your resolv.conf, if you have roaming mode enabled, Ubuntu dynamically re-creates resolv.conf on the fly for whatever network you are on. This is the way it's supposed to work. Often, however, you will find yourself on a network where you need to DHCP to get an IP, but you want to use a different DNS server than the default one (like OpenDNS.)

In order to do this, you will need to modify the dhclient.conf located in /etc/dhcp3/

$ sudo nano /etc/dhcp3/dhclient.conf

Inside of that file, you will want to prepend DNS servers to the resolve.conf. Prepending means that your specified DNS servers will be added to the beginning of the resolv.conf file (before the regular DNS servers,) resolving requests through your chosen DNS servers before any others. You can prepend your chosen DNS servers by adding the following line:

prepend domain-name-servers 123.123.123.123;

where 123.123.123.123 is the IP address of the DNS server that you want to use.
Note the semi-colon at the end of the line. In addition, you can specify multiple DNS servers by using a comma separated list such as:

prepend domain-name-servers 123.123.123.123,222.222.222.222;

where 123.123.123.123 is one DNS server and 222.222.222.222 is the other.


If you wish to supersede the normal DNS servers entirely, use:

supersede domain-name-servers 123.123.123.123;

Go ahead and write out the file (CTRL-O) and exit (CTRL-X) then restart your networking services:

$ sudo /etc/init.d/networking restart

(or disable/enable from the GUI)

You should be on your way to non-DHCP force-fed DNS servers!

Sphere: Related Content

0 comments: