Q: Everytime when I customized the resolv.conf file and restart the centOS, the resolv.conf has been restored by the NetworkManager. How to avoid that happen?
A: Basically you have to create two files:
The first is to tell the NetworkManager to run a script after a new interface comes up. Network Manager will run the scripts located in /etc/NetworkManager/dispatcher.d in order of how they are named. So if the file with the highest number is something like:
11-dhclient
You should create a new file that has a higher number so it will run last:
12-override-dns
You then put in this script a command to copy a custom resolv.conf overwrite the existing resolv.conf:
#!/bin/bash cp -f /etc/resolv.conf.myDNSoverride /etc/resolv.conf
Then you can create the custom resolv.conf file in /etc/resolv.conf.myDNSoverride with the settings you would like.
Such as to add the DNS servers.
Settings should now be preserved when you reboot or restart the network. You can test it by running:
service NetworkManager restart
and making sure the resolv.conf has the settings you wanted.
cat /etc/resolv.conf