How to stop NetworkManager service to modify resolv.conf file ?
Today we will see one of the most common issue that after rebooting system our resolv.conf file is getting updated everytime and our DNS client configuration is removed.
Let us see the steps we need to perform to stop Network Manager service updating the resolv.conf file.
1. Check Network Manager Service Status
[root@ngelinux01 ~]# service NetworkManager status Redirecting to /bin/systemctl status NetworkManager.service ● NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2023-08-22 12:57:48 IST; 22min ago Docs: man:NetworkManager(8) Main PID: 1506 (NetworkManager) Tasks: 3 (limit: 3355442) Memory: 11.8M CPU: 328ms CGroup: /system.slice/NetworkManager.service └─1506 /usr/sbin/NetworkManager --no-daemon Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0842] device (eno1): state change: config -> ip-config (r> Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0852] device (eno1): state change: ip-config -> ip-check > Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0859] device (eno1): state change: ip-check -> secondarie> Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0860] device (eno1): state change: secondaries -> activat> Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0862] manager: NetworkManager state is now CONNECTED_LOCAL Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0864] manager: NetworkManager state is now CONNECTED_SITE Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0864] policy: set 'System eno1' (eno1) as default for IPv> Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0865] device (eno1): Activation: successful, device activ> Aug 22 12:57:53 ngelinux01 NetworkManager[1506]: [1692689273.0868] manager: NetworkManager state is now CONNECTED_GLOB> Aug 22 12:57:55 ngelinux01 NetworkManager[1506]: [1692689275.8768] manager: startup complete
2. Make “dns=none” in NetworkManager.conf configuration file.
[root@ngelinux01 ~]# head -50 /etc/NetworkManager/NetworkManager.conf # Configuration file for NetworkManager. # # See "man 5 NetworkManager.conf" for details. # # The directories /usr/lib/NetworkManager/conf.d/ and /run/NetworkManager/conf.d/ # can contain additional .conf snippets installed by packages. These files are # read before NetworkManager.conf and have thus lowest priority. # The directory /etc/NetworkManager/conf.d/ can contain additional .conf # snippets. Those snippets are merged last and overwrite the settings from this main # file. # # The files within one conf.d/ directory are read in asciibetical order. # # You can prevent loading a file /usr/lib/NetworkManager/conf.d/NAME.conf # by having a file NAME.conf in either /run/NetworkManager/conf.d/ or /etc/NetworkManager/conf.d/. # Likewise, snippets from /run can be prevented from loading by placing # a file with the same name in /etc/NetworkManager/conf.d/. # # If two files define the same key, the one that is read afterwards will overwrite # the previous one. [main] dns=none #plugins=keyfile,ifcfg-rh
3. Make the file immutable as a precaution
[root@ngelinux01 ~]# lsattr /etc/resolv.conf ---------------------- /etc/resolv.conf [root@ngelinux01 ~]# chattr +i /etc/resolv.conf [root@ngelinux01 ~]# lsattr /etc/resolv.conf ----i----------------- /etc/resolv.conf [root@ngelinux01 ~]#