Leaderboard ad


Update Search Domains on Red Hat 7, CentOS 7 and Fedora using Network Manager Command Line Interface (nmcli)

Question sent in by Julio from New York, NY.

Q: I am runing Red Hat Enterprise Linux 7 Workstation and am having a hard time adding search domains.  My work has several domains and I want to be able to use the short names.  I have tried the network settings and don't see a place to add search domains. I have also added "search domain1 domain2" to resolv.conf but it gets replaced every reboot by Network Manager.  Any help?

A: This is because Gnome does not give you a place to enter search domains in their Network Settings GUI. Also, the /etc/resolv.conf file is generated every time the Network Manager process starts or restarts which overwrites the manual changes. 

Let's start with why someone would want to add search domains.  Let's say your office used a domain of example.com.  So the servers are named similar to server1.example.com.  If you add example.com to your search domains, you would be able to access the servers using the short name "server1".  The search domains are automatically appended to the end of host names.  If you add multiple search domains they will append one by one until they resolve in DNS.

So, to fix this you have two options...

You can run the Network Manager GUI configuration tool by running the following command:

sudo nm-connection-editor

Once the Network Manager Connection Editor opens, select the network adapter you want to change the settings for and click edit.  Go to the IPv4 Settings page and enter the domains in "search domains" field (separate multiple domains with a comma).

or use the Network Manager Command Line Interface (nmcli).  First run nmcli to find the name of the interface like so:

sudo nmcli

virbr0: connected to virbr0
bridge, 52:54:00:7B:B3:F0, sw, mtu 1500

em1: connected to em1
"Intel Ethernet Connection (3) I218-LM"
ethernet (e1000e), 83:7B:FB:41:6B:78, hw, mtu 1500
ip4 default
inet6 fe83::8043:90fb:ff4e:9590/64

wlp2s0: disconnected
"Intel Wireless 7265 (Dual Band Wireless-N 7265)"
wifi (iwlwifi), 62:EF:10:F9:3B:BE, hw

lo: unmanaged
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

virbr0-nic: unmanaged
tun, 52:54:00:7B:B3:F0, sw, mtu 1500

DNS configuration:
interface: em1

Now if you want to add the search domains to em1 interface use the nmcli command like so:

sudo nmcli con mod em1 ipv4.dns-search "domain1.local,domain2.local,domain3.local"

Check the configuration:

sudo nmcli con show em1 | grep dns-search

ipv4.dns-search:                        domain1.local,domain2.local,domain3.local
ipv6.dns-search:                        --

Now restart Network Manager:

sudo systemctl restart NetworkManager

Now when Network Manager restarts, it should generate the correct settings in /etc/resolv.conf

# Generated by NetworkManager
search domain1.local,domain2.local,domain3.local

Good Luck!

1 comment:

  1. I take pleasure in, lead to I discovered exactly what I used too be taking a liok
    for. You have ended my 4 day lengthy hunt!

    God Blerss you man. Have a great day. Bye