NetworkManager overwrites /etc/resolv.conf

Issues related to configuring your network
Post Reply
dagniel
Posts: 2
Joined: 2018/05/09 19:36:51

NetworkManager overwrites /etc/resolv.conf

Post by dagniel » 2018/05/09 21:31:07

Hello all!

I'm trying to figure out how to solve a specific problem related to the installation fo a framework that uses NetworkManager and dnsmasq (and configures them).

The background is like this. I have a cluster of multiple hosts, all running in a private network 192.168.150.0/24 with DHCP. They all have to be discoverable by name so one of the hosts acts like a dns nameserver. To get this to work I've made the configurations on all hosts (dns server + the rest- the clients) with specifying nameserver and the search domain in /etc/resolv.conf.
In order for the dns configuration file to not get overwritten by NetworkConfig I specified

Code: Select all

dns=none
under the [main] section in /etc/NetworkManager/NetworkManager.conf file. This works fine (on service restarts, both network and NetworkManager, /etc/resolv.conf remains the same and hosts can resolve each-other).

However, I've run an automated installation that made some changes to my hosts, including intalling dnsmasq and configuring it (+ a lot of other insallation) and now I'm experiencing a weird behaviour, that, I think, is related to the NetworkManager service/configuration.
At this point, there is a script in /etc/NetworkManager/dispatcher.d/ that's creating/configuring some files in /etc/dnsmasq.d and enabling the dnsmasq service. The script reads the nameservers and the search domains that it finds in /etc/resolv.conf, creates the config files in /etc/dnsmasq.d based on them and then rewrites a new /etc/resolv.conf with a new configuration.

The problem I have is that at a service restart for NetworkManager, the script seems to run on predefined version of /etc/resolv.conf. In other words, no matter what I write in /etc/resolv.conf, after a systemctl restart NetworkManager, the end result (/etc/resolv.conf + config files in /etc/dnsmasq.d/) looks precisely the same.

My question is where is this "default" configuration written? How come does NetworkManager service "overlooks" the actual content of the /etc/resolv.conf file upon restart?

Further more, by running a

Code: Select all

nmcli con show "System eth0"
on one of the hosts, I get

Code: Select all

...
IP4.ADDRESS[1]:                         192.168.150.22/24
IP4.GATEWAY:                            192.168.150.1
IP4.ROUTE[1]:                           dst = 169.254.169.254/32, nh = 192.168.150.1, mt = 100
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP4.DOMAIN[1]:                          openstacklocal
...
Those 2 DNS servers (Google) is precisely what I get written in the dnsmasq conf files, no matter the contents of the /etc/resolv.conf.
The equivalent config file for this interface doesn't specify any of these:

Code: Select all

cat /etc/sysconfig/network-scripts/ifcfg-eth0 
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth0
HWADDR=fa:16:3e:9f:e5:f3
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
Thanks in advance for your help,
Dan

User avatar
TrevorH
Forum Moderator
Posts: 22752
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: NetworkManager overwrites /etc/resolv.conf

Post by TrevorH » 2018/05/10 01:18:24

Add PEERDNS=no to your ifcfg file
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

dagniel
Posts: 2
Joined: 2018/05/09 19:36:51

Re: NetworkManager overwrites /etc/resolv.conf

Post by dagniel » 2018/05/10 09:26:52

Such a small thing...

It appears to be working, thank you very much TrevorH!

Post Reply