You have two ways to change DNS
- Modify the directive DNS1 directly in the interface configuration file, the configuration will reflect its DNS settings to /etc/resolv.conf after service network restart.
- Set the directive PEERDNS explicitly to no in the interface configuration file, and then modify /etc/resolv.conf
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID= ...
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR= ...
IPADDR=10.12.13.123
PREFIX=8
GATEWAY=10.0.0.1
DNS1=168.95.1.1
#DNS1=8.8.8.8
DOMAIN=example.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
...
NAME="System eth0"
PEERDNS=no
[root@localhost ~]# vi /etc/resolv.conf
nameserver 168.95.1.1
search example.com
Setting PEERDNS=no explicitly can make NIC configuration stop reflecting its settings (e.g. DNS and Search Domain) to /etc/resolv.conf, therefore, /etc/resolv.conf can be persistent after reboots. You may refer to Red Hat documentation for more about the directive PEERDNS at:
9.2. Interface Configuration Files
Here is the quote:
PEERDNS=answer
where answer is one of the following:
yes — Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default.
no — Do not modify /etc/resolv.conf.
[root@localhost ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 10.12.13.123 is already in use for device eth0...
[ OK ]