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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With