Adding additional DNS search domains when using DHCP

Here is a complete solution that works at least with 12.04:

sudo nano /etc/dhcp/dhclient.conf
# add next line (alternatively you can use append instead of prepend)
prepend domain-name "example.com other.example.com";
# before: request subnet-mask...

(you can also use sudo -e /etc/dhcp/dhclient.conf if you trust the default editor)

If you're on any sort of "professional" network that has its own DNS servers and/or if you've setup your own DNS service(s) on said network and also on your workstation, then, you might also want to comment-out this line:

# domain-name, domain-name-servers, domain-search, host-name,

--Doing so lets you use your own domain-name-servers, enabling your personalized domain-search to work much more smoothly, which is probably better than using whatever somebody else has setup for you. E.G.: I'm on the network 192.168.10.0; the company has name server 192.168.10.10 and 192.168.10.11 -- but, I run my own name server with a more extensive list of names on 192.168.10.20 (which will forward to 192.168.10.10 and .11 as needed). All my network configurations declare 192.168.10.20 and 8.8.8.8 and 8.8.4.4 (the Google name servers), but, DHCP will tend to override that preference, feeding me 192.168.10.10 as the default server. In the end... not requesting those aspects from DHCP makes for a much better network life.

Now restart the networking:

sudo service networking restart

(you can also use sudo /etc/init.d/networking restart with old rc scripts)


In more recent versions of Ubuntu, Network Manager allows you to add additional search domains and DNS servers while still using the values from DHCP.

  • Click on the Network Manager indicator and select Edit Connections... Select the connection you want to adjust, and click Edit. Depending on the type of the connection, you may have to switch tabs.
  • In the Editing dialog, switch to the IPv4 Settings tab (or the IPv6 Settings tab if you're using IPv6).
  • Leave it set at Automatic (DHCP). Simply fill in the Additional search domains field with a comma-separated list of domains, and click Save.
  • You may need to disconnect and reconnect.

Sorin's answer and Ib33X's answer are correct if you are not using the Network Manager. If you are using the Network Manager, then it appears that the Network Manager completely controls generation of the resolv.conf file (which is ultimately what the networking system uses for dns lookups). Changing the dhcpclient.conf is ineffective.

However, there is an (imperfect) solution if you are using the Network Manager:

  1. Make note of the DNS servers setup by DHCP by inspecting the resolve.conf file:

    cat /etc/resolv.conf

  2. Right-click on the Network Manager indicator and select Edit Connections...

  3. Select the connection you want to adjust, and click Edit. Depending on the type of the connection, you may have to switch tabs.
  4. In the Editing dialog, switch to the IPv4 Settings tab (or the IPv6 Settings tab if you're using IPv6).
  5. Change the Method from Automatic (DHCP) to Automatic (DHCP) addresses only.
  6. Copy the DNS servers you saved in step #1 into the DSN servers text box (sue commas to separate multiple entries).
  7. Enter each of the domain names to search by into the Search domains text box.
  8. Click Save...
  9. Disconnect and reconnect the connection.

The downsides of this approach is that you must specify both the DNS servers and the search domain names. It isn't possible to still pull the DNS server addresses from DHCP.

Additionally, the settings must be changed for each connection. I don't know of any way of changing the settings for all connections. However, this is often an advantage. For example, you might want different settings for your home wireless network and your work wireless network.