CentOS7: Network Manager is using wrong search domain

After a few hours of poking around, I was able to resolve this. It turns out, this was being set via DHCP:

nmcli -f ip4 device show eth0
IP4.DOMAIN[1]:                          ec2.internal

I was able to override IP4.DOMAIN[1] by overriding a network interface's ipv4.dns-search value:

nmcli connection modify uuid \`nmcli connection show --active | grep 802-3-ethernet | awk '{print $(NF-2)}' | tail -n 1` ipv4.dns-search d.sample.com

Or more simply,

nmcli connection modify System\ eth0 ipv4.dns-search "d.sample.com"

Then you have to restart NetworkManager

systemctl restart NetworkManager.service

I also found that because I was working with an Amazon instance, I needed to update my cloud.cfg file.

The /etc/resolv.conf file will always be overwritten when there is a change or update to the network. You can control what is written by editing files in the /etc/resolvconf/resolv.conf.d/ folder... namely the head file.

Place this in the /etc/resolvconf/resolv.conf.d/head file:

search testing01.d.sample.com

Now this will be the header of the /etc/resolv.conf each time it's updated.


For Redhat based systems, use these steps:

Edit your network script which is located at: /etc/sysconfig/network-scripts. You will see an entry for the network devices detected (i.e. ifcfg-eth0 for the network adapter eth0).

Edit this file (/etc/sysconfig/network-scripts/ifcfg-eth0):

Append this line:


Also run this command:

$ sudo hostnamectl set-hostname --static "testing01.d.sample.com"

You'll most likely have to reboot the system to make the changes take effect.