8

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?

ReynierPM
  • 843

12 Answers12

9

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Mio Rin
  • 3,040
3

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;

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
robert
  • 621
  • 2
  • 9
  • 18
  • I was facing this problem for many months now. I tried different solutions. Nothing solved the problem. I just installed resolvconf package according to your suggestion. It worked! – Ashfaqur Rahaman Sep 15 '21 at 22:16
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

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

Necrus
  • 11
1

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

A1Gard
  • 111
1

I encountered the same issue.
And below command solved it.

echo '[main]' > /etc/NetworkManager/conf.d/90-dns-none.conf
echo 'dns=none' >> /etc/NetworkManager/conf.d/90-dns-none.conf
systemctl reload NetworkManager

My environment is CentOS7.

reference https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/manually-configuring-the-etc-resolv-conf-file_configuring-and-managing-networking

0

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

GAD3R
  • 66,769
thaller
  • 1,556
  • 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

GAD3R
  • 66,769
  • 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
  • @ReynierPM please add NM_CONTROLLED=no to your ifcfg-enp0s31f6 file then test it. – GAD3R Nov 28 '16 at 13:51
  • That way I haven't network connectivity at all meaning no IP address or so ... – ReynierPM Nov 28 '16 at 14:03
  • @ReynierPM NM_CONTROLLED=no to prevent NM to configure your interface. change it to yes then add your dns to NetworkManager.conf – GAD3R Nov 28 '16 at 14:43
  • I am not following on your latest comment, can you add a step by step to your post? I am still having the problem and I've updated to Fedora 25 at this point – ReynierPM Jan 03 '17 at 18:06
  • Also I have updated the OP with further info since I am still having the issue – ReynierPM Jan 03 '17 at 18:56
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
hatted
  • 101
0

I have had the same problem on

Distributor ID: Debian Description: Debian GNU/Linux 10 (buster) Release: 10 Codename: buster .

On my system I am using dnsmasq for several reasons.

Therefore the DNS for system apps is localhost aka 127.0.0.1.

In the dnsmasq then I redirect some queries to the external DNS resolvers and some I resolve locally.

Long story short:

Because I was using static IP settings for my NIC, there was no setting made for DNS servers in the GUI of NetworkManager.

Therefore no resolv.conf was being generated.

Although most services were working, some were not.

The solution to make ALL services work was to enter 127.0.0.1 as DNS Server in the GUI of NetworkManager and restart that Service.

Kind regards.

0

To me, in Debian 10, it was connman. Indeed:`

$> ls -l /etc
.. .. 
resolv.conf -> /run/connman/resolv.conf 

I disabled connman, removed the file resolv.conf and re-created it as a regular file. After reboot finally it is still there.

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