Networking – Why is /etc/resolv.conf Deleted on Every Reboot?

dhcpfedoranetworkingnetworkmanagerresolv.conf

I am having an issue where DHCP (I though as I read in other similar topics) is clearing the /etc/resolv.conf file on each boot. I am not sure about how to deal with this since the post I have found (1, 2 and some others) are for Debian based distros or other but not Fedora.

This is the output of ifcfg-enp0s31f6 so for sure is DHCP:

cat /etc/sysconfig/network-scripts/ifcfg-enp0s31f6 
HWADDR=C8:5B:76:1A:8E:55
TYPE=Ethernet
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=no
IPV6_DEFROUTE=no
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s31f6
UUID=0af812a3-ac8e-32a0-887d-10884872d6c7
ONBOOT=yes
IPV6_PEERDNS=no
IPV6_PEERROUTES=no
BOOTPROTO=dhcp
PEERDNS=yes
PEERROUTES=yes

In the other side I don't know if Network Manager is doing something else around this.

Update: Content of NetworkManager.conf (I have removed the comments since are useless)

$ cat /etc/NetworkManager/NetworkManager.conf 
[main]
#plugins=ifcfg-rh,ibft
dns=none

[logging]
#domains=ALL

Can I get some help with this? It's annonying be setting up the file once and once on every reboot.

UPDATE 2

After a month I'm still having the same issue where file gets deleted by "something".

Here is the steps I did follow in order to make a fresh test:

  • Reboot the PC
  • After PC gets restarted open a terminal and try to ping Google servers of course without success:

    $ ping google.com
    ping: google.com: Name or service not known
    
  • Check the network configuration were all seems to be fine:

    $ cat /etc/sysconfig/network-scripts/ifcfg-enp0s31f6 
    NAME=enp0s31f6
    ONBOOT=yes
    HWADDR=C8:5B:76:1A:8E:55
    MACADDR=C8:5B:76:1A:8E:55
    UUID=0af812a3-ac8e-32a0-887d-10884872d6c7
    BOOTPROTO=static
    PEERDNS=no
    DNS1=8.8.8.8
    DNS2=8.8.4.4
    DNS3=192.168.1.10
    NM_CONTROLLED=yes
    IPADDR=192.168.1.66
    NETMASK=255.255.255.0
    BROADCAST=192.168.1.255
    GATEWAY=192.168.1.1
    TYPE=Ethernet
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=no
    
  • Restart the network service:

    $ sudo service network restart
    [sudo] password for <current_user>: 
    Restarting network (via systemctl):                        [  OK  ]
    
  • Try to ping Google servers again, with no success:

    $ ping google.com
    ping: google.com: Name or service not known
    
  • Check for file /etc/resolv.conf:

    $ cat /etc/resolv.conf 
    cat: /etc/resolv.conf: No such file or directory
    
  • File doesn't exists anymore – and this is the problem something is deleting it on every reboot

  • Create the file and add the content of DNS:

    $ sudo nano /etc/resolv.conf 
    
  • Ping Google servers this time with success:

    $ ping google.com
    PING google.com (216.58.192.110) 56(84) bytes of data.
    64 bytes from mia07s35-in-f110.1e100.net (216.58.192.110): icmp_seq=1 ttl=57 time=3.87 ms
    

Any ideas in what could be happening here?

Best Answer

In my experience, /etc/resolv.conf gets regenerated on boot, so any manual changes to it get reset.

To work around this, you can create /etc/resolv.conf.head (or .tail depending on which end of the file you want to add to) and insert the custom settings you want in there (usually nameserver changes). Then the contents of that file gets added automatically when /etc/resolv.conf is generated by NetworkManager (or whichever service is in charge of the file on your system).

If that doesn't work, you can modify /etc/resolvconf/resolv.conf.d/base -- it stores the "default" content for /etc/resolv.conf.

Related Question