Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop network manager from updating resolv.conf [closed]

I changed nameserver in /etc/resolv.conf but when I connected vpn in my CentOS, network-manager pushed my previous DNS back into /etc/resolv.conf.

I do not want network-manager to add DNS servers received from DHCP to my /etc/resolv.conf.

Any solution?

like image 762
Wajahat Avatar asked Oct 28 '25 00:10

Wajahat


2 Answers

The "brute force" way to prevent a file being updated in Linux could be to use chattr, for example you could do:

chattr +i /etc/resolv.conf

To remove the i - Immutable attribute so that you could modify the file again run:

chattr -i /etc/resolv.conf

Another way could be to configure /etc/NetworkManager/NetworkManager.conf to not modify the DNS:

[main]
dns=none

From the man:

dns
       Set the DNS (resolv.conf) processing mode.

       default: The default if the key is not specified. NetworkManager will update
       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.

       none: NetworkManager will not modify resolv.conf.
like image 118
nbari Avatar answered Oct 31 '25 02:10

nbari


setting dns=none still might allow for the networkmanager to break things - if DOMAIN is also specified in the ifcfg-file, NM will still write the file but skipping any dns:es instead recommend setting the following under [main] section:

rc-manager=unmanaged 

this tells networkmanager not to touch /etc/resolv.conf at all according to documentation

like image 20
Daniel Hrynczenko Avatar answered Oct 31 '25 02:10

Daniel Hrynczenko