1 min read

Adding multiple search domains to network connection with nmcli

Adding multiple search domains to network connection with nmcli


This is for my own reference. These days for my lab infrastructure, I automate nearly everything with Ansible. Today I added another dns domain which I will be migrating to eventually and needed to add an additional dns domain to my resolver on this host which is managed by NetworkManager.

Since RHEL8, I became accustomed to managing all network connections in the OS with nmcli and this time I just needed to add an additional search domain (lab.acanorex.io) to the local resolver to go from this:

# resolv.conf
search voltron.xyz
nameserver 172.25.49.253
nameserver 172.25.49.254

To this:

# resolv.conf
search voltron.xyz lab.acanorex.io
nameserver 172.25.49.253
nameserver 172.25.49.254

There is actually an option to configure NetworkManager not to update /etc/resolv.conf by using the NetworkManager option dns=none as per this KCS article: https://access.redhat.com/solutions/894753 but in true vanilla boy Red Hat fashion, I let NetworkManager take control of it, so if I were to edit resolv.conf file manually, the changes would have been lost after a reboot.

This is how you add multiple dns search domains using nmcli:

nmcli con mod <id> ipv4.dns-search "x.x.x.x,y.y.y.y"

This is the actual example that I used in my setup:

# Current settings
(openstack-tools) [burbles@utility ~]$ nmcli con show enp1s0 | grep ipv4.dns-search
ipv4.dns-search:                        voltron.xyz

# Command to change it
(openstack-tools) [burbles@utility ~]$ sudo nmcli con mod enp1s0 \
ipv4.dns-search "voltron.xyz,lab.acanorex.io"

# Verification of changes
(openstack-tools) [burbles@utility ~]$ nmcli con show enp1s0 | grep ipv4.dns-search
ipv4.dns-search:                        voltron.xyz,lab.acanorex.io

# Reload the connection after changes
(openstack-tools) [burbles@utility ~]$ sudo nmcli con reload

A short and sweet reference for later.