In older versions of the NetworkManager gui there was a field for the search domain to be written into /etc/resolv.conf, but it was dropped by the time Ubuntu 18.04 LTS shipped. You can add it by editing the system-connections file directly, but running the appropriate nmcli commands is the right way to do it. Note that Ubuntu Server 18.04, which use netplan and systemd-networkd by default, is completely different. Ubuntu 20.04 involves even more variation (see comments below). It's enough to drive someone to Debian proper...
First, get the name of the interface you want to set a search domain on:
$ nmcli con show
Assuming that the target interface will be "Wired connection 1" (note, interface names are case-sensitive):
$ sudo nmcli con mod 'Wired connection 1' ipv4.dns-search "example.com"
$ nmcli con show 'Wired connection 1' | grep dns-search
If you're using DHCP ("method=auto") in Ubuntu 18.04 and later, the above fix will be ignored.
If you really want to force a domain name into resolv.conf, you need to edit /etc/dhcp/dhclient.conf to add this directive:
supersede domain-name "example.com";
In general I always try to resolve this issue at the DHCP server by making sure I pass the search domain value to clients. Most routers with a DHCP service will provide some way to specify this configuration detail. This is what that would look like in a standard ISC DHCPD configuration (/etc/dhcp/dhcpd.conf):
subnet 10.1.0.0 netmask 255.255.255.0 {
option routers 10.1.0.1;
option subnet-mask 255.255.255.0;
option domain-name "example.com";
option domain-search "example.com";
The "domain-name" option is ignored by Linux clients, but needed by Windows machines. The "domain-search" option is what Linux machines use, while Windows machines will ignore it.
- Ubuntu 18.04 LTS Desktop and later default to using NetworkManager to control networking, with systemd-resolved handling name resolution. But in my experience the default Ubuntu config for systemd-resolved links the wrong file to /etc/resolv.conf: /run/systemd/resolve/stub-resolv.conf.
On a properly configured system the other file in that systemd/resolve directory, named resolv.conf, should look like this:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 10.0.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
So if you change the link like this:
$ sudo rm /etc/resolv.conf
$ sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
then things should work the way they're supposed to.
Thank you for the reply, but what I am trying to do is to set one, global property that would be applied to every WIFI connection I will make in future. I'm using a laptop to connect to numerous different WIFI networks, so I would like to skip configuring dns-search and dns-servers for every connection.
Sorry that I did not explain this clearly enough.
I found a config property for NetworkManager that should work, but setting it did not change my resolv.conf.
[https://developer.gnome.org/NetworkManager/stable/NetworkManager.conf.html] documents section "global-dns" with property "searches" that should do exactly what I need, but it doesn't so far.