CentOS 7 – /etc/resolv.conf Resetting on Network Restart

centos7linuxnetworking

This is my /etc/resolv.conf on CentOS 7:

# Generated by NetworkManager
search example.com
nameserver 10.0.2.3
~                   

This is my /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=dhcp
DEFROUTE="yes"
ONBOOT="yes"
TYPE=Ethernet
PERSISTENT_DHCLIENT="yes"
ZONE=public
DNS="192.168.33.11"
PROXY_METHOD=none
BROWSER_ONLY=no
IPADDR=192.168.33.11
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03

Whenever i try to restart the network using systemctl restart network after adding nameserver 192.168.33.11 it gets reset to the one on above. What changes should I make to ifcfg-eth0 so that i my new nameserver doesn't get erased even on restart.

Best Answer

# echo "PEERDNS=no" >>  /etc/sysconfig/network-scripts/ifcfg-eth0

that can prevent DHCP to overwrite /etc/resolv.conf

You should disable the NetworkManager service if you like edit manualy the files in the /etc/sysconfig/network-scripts directory.

# systemctl status NetworkManager

If commands returns "active", then you should disable it.

# systemctl stop NetworkManager.service
# systemctl disable NetworkManager.service
# systemctl restart network.service
# systemctl enable network.service

Then you can edit /etc/resolv.conf

Related Topic