I'm running a CentOS 7 Virtual machine and it's picking up the DNS nameservers from my Fedora 27 system via DHCP I believe. I am trying to change the DNS nameserver in /etc/resolv.conf to google name servers. It's different on my fedora 27, when I do that and do systemctl restart network it goes back to the same nameservers on the fedora 27.

Is there a way to override that?

I believe I have to do something in /etc/sysconfig/network-scripts/

I am connected via ethernet enp0s3 on the vm and of course bridged on virbr0


The network interface of the VM is configured to accept DNS from dhcp only. Change the interface settings.

Network interface configuration files are in /etc/sysconfig/network-scripts/.

Say it's a kvm vps and the network interface is eth0. Edit the file /etc/sysconfig/network-scripts/ifconfig-eth0 and add the following for Google's IPv4 nameserver


Then restart networking as follows

sudo service network restart

You may use any other nameserver.

The above mentioned nameservers will be added in resolve.conf and PEERDNS=no directive will stop dhcp from altering nameserver.

Another way out is making resolv.conf read only even for root as follows

chattr +i /etc/resolv.conf

If you want to edit the file latter use chattr -i /etc/resolv.conf before editing.

P.S. PEERDNS=no works only with RHEL based system including RHEL, CentOS and Fedora.

| improve this answer | |
  • Using systemd to restart the network service: sudo systemctl restart network.service – fpmurphy Dec 28 '17 at 1:38
  • That's fine. You can use either systemctl or service. systemctl is newer implementation in Fedora like systems. service is obsolete and redirect to systemctl. I use service because it's more generic. – Abhik Bose Dec 28 '17 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.