54

I recently installed Ubuntu GNOME on my work computer, replacing Windows 7, because I will be doing a lot of Linux development work.

Many of our configuration and development scripts use shortened URLs for servers on the company network. That is, they use http://server rather than http://server.location.company.com. I never had problems with these URLS in Windows, but I have not been able to get them to work correctly in Ubuntu. It is not feasible for me to simply type the entire fully-qualified URL because the shortened form is used all over the place in various scripts, but I am able to access the long-form URLs.

When I connect to the company's VPN using the Dell SonicWall NetExtender VPN Client, the shortened URLS do work correctly.

Based on the research I have done so far, I think that I need to configure location.company.com as a search domain on Ubuntu, but my attempts at doing this have failed so far. Here is what I have tried:

  • In the "Network Connections" app, edit my wireless connection. Under the IPv4 tab, select Automatic (DHCP) addresses only. Then type in location.company.com as a search domain, and put our DNS server in as well. This made no noticeable difference.
  • Modifying dhclient.conf as described here.
  • Running dpkg-reconfigure resolvconf to make sure that it dynamically updates resolv.conf.

I am also worried that at this point I have tried several different things and they could be interfering with each other. I know that some parts of this configuration changed in the last couple of years with Ubuntu, and it can be hard to find the most current information. It is not completely clear to me how network-manager, resolvconf, dhclient, and other configuration files work together in the newest versions of Ubuntu.

So, my question: How can I configure my computer to make the short-form URLs work correctly in Ubuntu 14.10?

Or, which network configuration programs should I be using to do this, how should I configure them, and how can I verify that they are working correctly?

Thanks for your help! Let me know if I can provide any additional info.

Edit: Here is my /etc/resolv.conf, which I believe was generated by resolvconf.

# Add Company Nameservers and Domain
nameserver 192.168.200.53
nameserver 192.168.200.65
search location.company.com
nameserver 127.0.1.1
search location.company.com
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search hsd1.co.comcast.net
2
  • Did you ever solve this? Mar 31, 2016 at 13:05
  • Quick Update: At some point I did a clean install of a more recent version of Ubuntu. Maybe 16.04? Anyway, I haven't had any issues and haven't had to reconfigure anything since then, and I'm now on 18.10.
    – mkasberg
    Feb 8, 2019 at 20:26

5 Answers 5

45

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.

13
  • 1
    by default dig doesn't auto append the domain stuff like the other do. However, "dig +search test" does. Feb 11, 2015 at 4:11
  • @DougSmythies: added..
    – heemayl
    Feb 11, 2015 at 15:20
  • I modified /etc/resolvconf/resolv.conf.d/base with nameserver and search entries. I'm now seeing the following behavior: $ host server server.location.company.com is an alias for server001.location.company.com. server001.location.company.com has address 192.168.200.103 $ ping server ping: unknown host server. Any idea what could be causing this?
    – mkasberg
    Feb 11, 2015 at 17:07
  • 3
    @mkasberg: Certain portion is missing in your last message..also note that after making any change in resolvconf run sudo resolvconf -u.
    – heemayl
    Feb 11, 2015 at 17:12
  • @mkasberg: Put it in /etc/resolvconf/resolv.conf.d/head..You DNS server has the entry for server.location.company.com, right?
    – heemayl
    Feb 11, 2015 at 17:59
38

I'm running 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:

systemctl restart systemd-resolved
3
  • 1
    systemctl syntax is COMMAND [UNIT] order so this should be systemctl restart systemd.resolved
    – karatedog
    Jun 24, 2021 at 9:31
  • 3
    Not quite @karatedog , should be systemctl restart systemd-resolved or systemctl restart systemd-resolved.service. Oct 25, 2021 at 6:51
  • 1
    @OscarGarcia You are right, I focused on solely the order and missed the dash instead of the dot.
    – karatedog
    Oct 29, 2021 at 9:36
19

I was looking for a solution to this issue for Ubuntu Focal 20.04, as my local domain was not appending to hostnames.

On most unix-like OS like Solaris, Debian, etc. the solution is to add a line with 'search domain.name' to /etc/resolv.conf but modern Ubuntu releases use systemd-resolved now, so I had to figure out what to do.

Thankfully, it's still only one line - just using the resolvectl command now instead of editing a text file:

# resolvectl domain <ifname> domain.name

(you can find your ifname by invoking ip addr or resolvectl status)

Note: This change is not permanent, for a permanent solution please see the update below

To verify it's working, make sure domain is listed by systemd-resolved by invoking:

user@host:/$ resolvectl status | tail

DefaultRoute setting: yes
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
  Current DNS Server: 192.168.1.2
         DNS Servers: 192.168.1.2
                      192.168.1.3
          **DNS Domain: domain.name**

and that it's in the auto-generated /etc/resolv.conf by invoking:

user@host:/$ tail /etc/resolv.conf

nameserver 127.0.0.53
options edns0
**search domain.name**

And try ssh or http using a hostname instead of a FQDN to see if the configured local domain resolves automatically.

I think my solution is the easiest and least confusing option - it's probably worth at least trying first in case it works for you before exploring the solutions posed in other answers.

Update 2-20-2020:

I noticed this change is not permanent. As per this question DNS set to systemd's 127.0.0.53 - how to change permanently? I learned that the permanent configuration is stored in /etc/systemd/resolved.conf - just uncomment Domains= and write your domain in there:

[Resolve]
#DNS=
#FallbackDNS=
Domains=domain.name
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=yes
#DNSStubListener=yes
#ReadEtcHosts=yes
2
  • @AveryFreedman Thank you so much for that update. It finally gave me a couple pieces of information that were missing in configuring my own network. It took me 9 months to get local DNS resolution working. I've done network administration for several decades and this level of difficulty is one of the reasons Linux will not replace Windows - Linux is still pretty user-unfriendly.
    – Suncat2000
    Jan 1, 2023 at 21:05
  • Good point about resolved.conf, but what's the magic command to apply the configuration change? I tried with a drop-in file in /etc/resolved.conf.d/, but not sure what's the incantation. Oct 30, 2023 at 16:01
9

From 16.04 on, the Advanced Network Configuration tool is only accessible via the command line:

sudo nm-connection-editor

The search domain can be configured on the IPvX Settings tab.

enter image description here

For further details, see Thomas Ward's excellent answer.

1

In my case, Adding search domain under /etc/resolvconf/resolv.conf.d/tail And restarting network manager And restarting my VPN worked.

Issue I was facing was, that my Org provided custom DNS that was not accessible.

Solution:

Add search my.orgdomain.com in /etc/resolvconf/resolv.conf.d/tail

After saving run sudo service network-manager restart

Restart VPN

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .