• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : DNS servers in /etc/resolv.conf change after a reboot/network service restart. How to make them permanent

by admin

You would face this issue after a reboot or a network service restart. This usually happens as the scripts /etc/sysconfig/network-scripts/ifup-post and /etc/sysconfig/network-scripts/ifdown-post checks for the parameters “RESOLV_MODS=no” or “PEERDNS=no” in the network interface configuration file such as /etc/sysconfig/network-scripts/ifcfg-*. If these either of these parameters are not present, it will replace the contents of /etc/resolv.conf with /etc/resolv.conf.save. By default, PEERDNS and RESOLV_MODS are null.

You would also see messages shown below in the /var/log/messages file:

Oct 10 12:40:52 hostname NET[22961]: /etc/sysconfig/network-scripts/ifdown-post : updated /etc/resolv.conf
Oct 10 12:40:57 hostname NET[23256]: /etc/sysconfig/network-scripts/ifup-post : updated /etc/resolv.conf

How to make entries in /etc/resolv.conf permanent

1. The /etc/resolv.conf file will be overwritten if any network interfaces use DHCP for activation. To prevent this, ensure such interfaces have PEERDNS=no set in their ifcfg file, for example:

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=dhcp
PEERDNS=no

2. The ifcfg-file directives DNS1 and DNS2 can also lead to modification of resolv.conf. To prevent this, either remove said directives or use chattr(1) to make resolv.conf immutable to changes, i.e.:

# chattr +i /etc/resolv.conf

Filed Under: Linux

Some more articles you might also be interested in …

  1. groupadd Command Examples in Linux
  2. CentOS / RHEL : How to setup session idle timeout (inactivity timeout) for ssh auto logout
  3. How to disable a specific command for a specific user in Linux
  4. jpegtran Command Examples in Linux
  5. What is ioremap()
  6. How to debug systemd boot process in CentOS/RHEL 7 and 8
  7. dkms Command Examples in Linux
  8. CentOS / RHEL : Managing password ageing for users using chage (with practical Examples)
  9. How to Add Network Printer via Command Line in CentOS/RHEL
  10. How to Resize / Expand a Btrfs Volume / Filesystem

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright