Leaderboard ad

1.18.2018

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
"virbr0"
bridge, 52:54:00:7B:B3:F0, sw, mtu 1500
inet4 192.168.122.1/24

em1: connected to em1
"Intel Ethernet Connection (3) I218-LM"
ethernet (e1000e), 83:7B:FB:41:6B:78, hw, mtu 1500
ip4 default
inet4 192.168.38.83/22
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
"lo"
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

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

DNS configuration:
servers: 192.168.16.40 192.168.16.10
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

output:
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
nameserver 192.168.16.40
nameserver 192.168.16.10

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

    ReplyDelete