6

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?

  • 3
    may PEERDNS=no help you – Ipor Sircer Nov 15 '16 at 15:11
  • @IporSircer no, I have changed the value and restart the PC, same result, no DNS information. BTW do I need to restart the PC or service network restart would be enough? – ReynierPM Nov 15 '16 at 15:20
  • Try chattr +i /etc/resolv.conf – GAD3R Nov 16 '16 at 19:02
  • @GAD3R not working: chattr: Operation not supported while reading flags on /etc/resolv.conf – ReynierPM Nov 16 '16 at 19:37
  • Which Fedora version (and Spin/Edition) are you using? – mattdm Nov 24 '16 at 18:49
5

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).

  • This workaroudnd isn't working either, I've tried and after restart /etc/resolv.conf is empty – ReynierPM Nov 28 '16 at 13:21
2

I think you were right on track.

It's working for me now, but I didn't do the:

dns=none

on the:

/etc/sysconfig/network-scripts/ifcfg-enp0s31f6

After I restarted the network manager, it automatically created the resolv:

sudo service NetworkManager restart

I rebooted and it still worked.

1

I had the same problem. It was soved by installing the resolvconf package. Since I am on Debian I can not test, but may help this tip:

  1. open (or create) as sudo: /etc/dhcp/dhclient.conf

  2. add: prepend domain-name-servers 127.0.0.1;

1

"Have you tried setting your resolv.conf file to have immutability after putting whatever content you want?."

pretty sure this keeps the /etc/dhcp/dhclient.conf from doing its job and your DNS never resolves anyway. At best this is frustrating and at worst freezes things up as your computer continuously tries to run that file and establish a connection. I think the key is in editing "/etc/dhcp/dhclient.conf" instead of resolv.conf directly, as that is the file that writes to resolv.conf on reboot.

  • Please edit your post to focus on your suggestion (i.e., the last sentence of your answer) and de-emphasize your critique of the other answer. – G-Man Aug 11 '18 at 16:38
0

Probably NetworkManager is configuring resolve.conf. if you don't want that, change rc-manager setting in NetworkManager.conf. See man NetworkManager.conf.

  • 1
    Nop, that's not the problem. I am reading this in docs none: NetworkManager will not modify resolv.conf. This implies rc-managerunmanaged and I am seeing this on /etc/NetworkManager/NetworkManager.conf [main] dns=none – ReynierPM Nov 22 '16 at 13:19
0

To prevent resolv.conf to be update at boot time, you should make the following changes:

Change PEERDNS=yes to PEERDNS=no

PEERDNS=no

This will prevent network service from updating /etc/resolv.conf with the DNS servers received from a DHCP server.

mentioned on @Ipor Sircer comment's

  • 1
    PEERDNS is set to no (see OP) now will BOOTPROTO=static change to static IP address instead of dynamic? If that's the case then this will not fix the issue. – ReynierPM Nov 28 '16 at 13:17
  • @ReynierPM right – GAD3R Nov 28 '16 at 13:18
  • I am not using NM at all, I mean is a tool in the GUI but I never touch it, can I disable it to prevent this behavior? People using DHCP on the same office gets DNS and Internet connection so I don't know what is happening here and I am tempted to disable NM, what do you think? – ReynierPM Nov 28 '16 at 13:27
  • @ReynierPM can you add the contents of NetworkManager.conf – GAD3R Nov 28 '16 at 13:40
  • Done, in the OP – ReynierPM Nov 28 '16 at 13:46
0

First You must sure resolvconf service active.

sudo service resolvconf status   

Active: active (exited) since

If the service active remove resolvconf:

sudo apt-get purge resolvconf

Then if after remove or this is not active or service not found:

sudo apt-get update
sudo apt-get install resolvconf

Then restart service:

sudo service resolvconf restart

now see the /etc/resolv.conf:

cat /etc/resolv.conf 

Must be exists:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN # 127.0.0.53 is the systemd-resolved stub resolver. # run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.1

0

I got the same problem when I install Debian 9.5 with GUI today. I do not have this problem when I install it without GUI. Finally, I found the solution from this link https://wiki.debian.org/resolv.conf. The DHCP started automatically even I set network manually when I was installing it. You should disable the DHCP to stop this problem.

echo 'make_resolv_conf() { :; }' > /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone
chmod 755 /etc/dhcp/dhclient-enter-hooks.d/leave_my_resolv_conf_alone

If that does not solve your problem, then I added a new line in the DHCP client file.

vi /etc/dhcp/dhclient.conf

prepend domain-name-servers 127.0.0.1;

Next, I remove the resolvconf and network-manger packages.

apt-get --purge remove resolvconf network-manager

Finally, if you still got the problem, you should setup your resolv.conf file and then lock this file by the following command. (It does not work if your resolv.conf is a symbolic link.)

chattr +i /etc/resolv.conf
-2

Have you tried setting your resolv.conf file to have immutability after putting whatever content you want?.

You may want to use chattr +i /etc/resolv.conf or with sudo.

By doing this we avoid overwrite.

Unless it is getting deleted, it might give initial insight.

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.