How do I configure the search domain correctly?

Solution 1:

Search domain means the domain that will be automatically appended when you only use the hostname for a particular host or computer. This is basically used in a local network.

Lets say you have a domain name like xyz.com (it may be available globally or may be local only) and you have 100 computers in the LAN. Now you want this domain name to be automatically appended when you look for any computer by just hostname of the computer. If the domain name to be appended is xyz.com then the search domain should look like:

dns-search xyz.com ##If you put this into /etc/network/interfaces

or

search xyz.com ##If you put this into /etc/resolvconf/resolv.conf.d/base|head|tail

Now how do you check if its working properly, just use ping or any DNS resolving program like host, nslookup , dig.

For example if a host is test having the IP 192.168.1.5 then using host:

host test
test.xyz.com has address 192.168.1.5

Now as dig does not use the search list/domain by default you need to use it like dig +search test to enable appending search domain.

Using nslookup:

nslookup test
Server:     192.168.1.11
Address:    192.168.1.11#53

Name:   test.xyz.com
Address: 192.168.1.5

Here 192.168.1.11 is your local DNS server which has the IP address for the host test.xyz.com (notice the full form) that is 192.168.1.5. The DNS server will resolve the hostname test.xyz.com to IP 192.168.1.5 but will not resolve anything for only test as it does not have any entry like so.

So, what search domain is doing in our case is that it is automatically appending a domain name to make it a FQDN when we are just using the hostname to look up a computer.

Solution 2:

I'm runnig Bionic Beaver and my resolv.conf says:

# This file is managed by man:systemd-resolved(8). Do not edit.

so my solution was to edit /etc/systemd/resolved.conf , option Domains= according to docs and then restart systemd-resolved:

service systemd-resolved restart