How can I prevent NetworkManager from modifying the /etc/resolv.conf file?
Environment
- Red Hat Enterprise Linux 10
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 7
- NetworkManager
Issue
- NetworkManager modifies the resolv.conf file and any manual changes there are lost
- How to prevent the
/etc/resolv.conffile from being overwritten by NetworkManager?
Resolution
-
In main section in /etc/NetworkManager/NetworkManager.conf file, define the dns parameter with a value of none:
# vi /etc/NetworkManager/NetworkManager.conf [main] dns=none -
Restart the NetworkManager service:
# systemctl restart NetworkManager -
Or the following works for RHEL8 and RHEL9.
# cat << 'EOF' > /etc/NetworkManager/conf.d/90-dns-none.conf [main] dns=none EOF # systemctl reload NetworkManager
Root Cause
-
Per the NetworkManager.conf man page:
dns Set the DNS (resolv.conf) processing mode. If the key is unspecified, default is used, unless /etc/resolv.conf is a symlink to /run/systemd/resolve/resolv.conf, /lib/systemd/resolv.conf or /usr/lib/systemd/resolv.conf. In that case, systemd-resolved is chosen automatically. default: NetworkManager will update /etc/resolv.conf to reflect the nameservers provided by currently active connections. dnsmasq: NetworkManager will run dnsmasq as a local caching nameserver, using a "split DNS" configuration if you are connected to a VPN, and then update resolv.conf to point to the local nameserver. It is possible to pass custom options to the dnsmasq instance by adding them to files in the "/etc/NetworkManager/dnsmasq.d/" directory. Note that when multiple upstream servers are available, dnsmasq will initially contact them in parallel and then use the fastest to respond, probing again other servers after some time. This behavior can be modified passing the 'all-servers' or 'strict-order' options to dnsmasq (see the manual page for more details). unbound: NetworkManager will talk to unbound and dnssec-triggerd, providing a "split DNS" configuration with DNSSEC support. /etc/resolv.conf will be managed by dnssec-trigger daemon. systemd-resolved: NetworkManager will push the DNS configuration to systemd-resolved none: NetworkManager will not modify resolv.conf. This implies rc-manager unmanaged
SBR
Product(s)
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.