Page 1 of 1

/etc/resolv.conf being rewritten

Posted: 2019/02/01 17:29:18
by iwishitwouldwork
Machine has 2 NICs, eno1 and eno2.
My problem: /etc/resolv.conf keeps being rewritten. I wanted to
set this up statically. But it was being re-written after each reboot.

The OS is Centos 7

Code: Select all

# uname -a
Linux fs.jgscrater.com 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov 29 14:49:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
I wondered whether the problem was related to resolvconf, but no.

Code: Select all

# updatedb
# locate resolvconf
#
I disabled (and stopped, and masked) as follows:

Code: Select all

# systemctl -q -a | grep NetworkManager
* NetworkManager-wait-online.service    masked    inactive dead      NetworkManager-wait-online.service
* NetworkManager.service                    masked    inactive dead      NetworkManager.service
I've checked my named.conf (in frustration) and it has no references to the
wrong answer (10.2.1.2) or the right answer (10.1.1.2) so that's not it.
I've checked the dns files (forward, reverse) and they're correct.
My dhcpd.conf file is correct (though it should be moot, given the ifcfg-eno* files
to follow).

ifcfg-eno1

Code: Select all

[root@fs network-scripts]# more eno1
#	DEVICE
UUID=b046149c-f74c-4d0f-a6ed-5652f758ca6e
HWADDR="0C:C4:7A:B2:7B:74"
ONBOOT="yes"
#	NETBOOT
IPV6INIT="no"
BOOTPROTO=none
TYPE="Ethernet"
NAME="eno1"
#
DNS1=10.1.1.2
DNS2=8.8.4.4
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
#
#	fs
IPADDR0=10.1.1.2
PREFIX0=16
GATEWAY0=10.1.1.2

ifcfg-eno2

Code: Select all

ONBOOT="yes"
#	NETBOOT
#	this uuid is the one from installation.
UUID=7266e473-4b66-4aa4-b4de-667ae090d32b
IPV6INIT="no"
BOOTPROTO=none
TYPE="Ethernet"
NAME="eno2"
#
#	????!!!!  Here is the "fix"
DNS1=10.1.1.2
DNS2=8.8.4.4
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
HWADDR="0C:C4:7A:B2:7B:75"
#
#	dns
IPADDR0=10.2.1.2
PREFIX0=16
GATEWAY0=10.2.1.2
I've disconnected eno2 as well. Notice the "no carrier"

Code: Select all

# ip addr
-- snip --
2: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
-- snip --
Yeah, this was a desperation move.



Okay, so I've "fixed" my problem, by changing DNS1 in the eno2 file.
What I hoped for was this:
eno1 is the "primary" NIC.
I wanted to write the /etc/resolv.conf file for myself.
At worst, I wanted the /etc/resolv.conf file to depend on the eno1 file.
But I didn't want any networking file to be re-written behind my back.

What I got was this:
The DNS1 entry in the eno2 file was re-setting the /etc/resolv.conf file.
What's doing that? why can't I stop that?

Thanks.
j.

Re: /etc/resolv.conf being rewritten

Posted: 2019/02/01 17:48:37
by TrevorH
You shouldn't have DNSx= in both config files as that tells it to alter resolv.conf whenever any changes happen on either connection.

If you don't want it to touch the contents of the file then remove all DNSx= parameters from all ifcfg files and add PEERDNS="no" instead. Now you are solely responsible for setting the content of /etc/resolv.conf yourself.

Re: /etc/resolv.conf being rewritten

Posted: 2019/02/01 20:05:34
by iwishitwouldwork
Aha! Well, I missed that entirely. Thanks. I will correct my error.

j.

Re: /etc/resolv.conf being rewritten

Posted: 2019/10/22 15:15:00
by jfranzoy
I've found that setting PEERDNS="no" in /etc/sysconfig/network-scripts/ifcfg-eth0 configuration file did not prevent dhcp-client script from updating /etc/resolv.conf.

Then I tried setting
PEERDNS="no"
export PEERDNS

and now, ifdown/ifup did work.

Is it a bug in dhcp-client script or its caller? Or it is the intended behaviour?

Re: /etc/resolv.conf being rewritten

Posted: 2019/10/23 17:31:28
by jlehtone
You have two interfaces with static config. Neither uses dhcp. Therefore, neither should run dhclient.

You have NetworkManager packages in the system, even though masked. You presumably let network.service to start the interfaces. However, you don't explicitly say in config that NM is not allowed to manage these. I'm not quite sure (for I've shifted to NM), but the network.service's ifup*-scripts might wrap to calling NM. Nevertheless, that does not explain why dhclient would start.

You also have
DEFROUTE="yes"
on both and both interfaces suggest a default gateway.
However, there can be (by definition of the word) only one default.