14

How can I add additional DNS search domains to a network connection which is configured using DHCP?

At work, we have several sub-domains (test.example.com, dev.example.com, etc), and I've grown tired of perpending the sub-domain every time I need to access a server in one of the sub-domains.

Jim Hurne
  • 343

6 Answers6

8

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.
Nick H
  • 253
7

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)

sorin
  • 10,155
6

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.

Jim Hurne
  • 343
2

in ubuntu 11.10 edit file /etc/dhcp/dhclient.conf and add this line

append domain-name "domain.com";

Then restart your network.

/etc/init.d/networking restart
pkhamre
  • 103
Ib33X
  • 240
1

I've wanted to do this for… well, at least since Ubuntu started using the systemd resolver. It turns out the simple way to ensure ALL connections get the full domain list automatically is to use /etc/systemd/resolved.conf.

To add .local,.home, and .taileeNNN.ts.net (your tailscale network), add this line:

Domains=local home taileeNNN.ts.net

From man resolved.conf:

       Domains=
           A space-separated list of domains, optionally prefixed with "~", used for two distinct purposes described below. Defaults to the empty
           list.

       Any domains not prefixed with "~" are used as search suffixes when resolving single-label hostnames (domain names which contain no dot),
       in order to qualify them into fully-qualified domain names (FQDNs). These "search domains" are strictly processed in the order they are
       specified in, until the name with the suffix appended is found. For compatibility reasons, if this setting is not specified, the search
       domains listed in /etc/resolv.conf with the search keyword are used instead, if that file exists and any domains are configured in it.

Auspex
  • 1,200
-1

Try below in this case when users gets ip address from dhcp server it gets mulitple dns servers

/etc/dhcp3/dhcpd.conf:

ddns-update-style none;

ignore client-updates;

authoritative;

default-lease-time 1209600;

max-lease-time 1814400;

option local-wpad code 252 = text;

--- Domain name servers, tells the clients which DNS servers to use.

option domain-name-servers 10.0.0.15, 8.8.8.8, 192.168.1.1;

option time-offset 0

kam gos
  • 106
  • The question is geared toward how to configure a connection using DHCP, i.e. it's about a DHCP client, not server. – Josip Rodin Jan 18 '16 at 18:58