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.