3

I use a static IP for my RPi:

root@rpi2:/etc# cat /etc/network/interfaces
auto lo
iface lo inet loopback
allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.0.2
        netmask 255.255.255.0
        gateway 192.168.0.254
        wpa-essid myssid
        wpa-psk mykey
        dns-nameservers 192.156.0.254

/etc/resolv.conf (which is a plain file, not a link) gets rewritten at each reboot with

# Generated by resolvconf
nameserver 127.0.0.1

I do not even have resolvconf installed!

root@rpi2:~# aptitude search resolvconf
p   resolvconf  - name server information handler

How can I disable this overwriting? (short of chattr +i which is an ugly hack)

2
  • I'm still confused by what exactly the thing is (the old method appears to mostly works for me...), but apparently there is some new way to configure the internet, see here. Which version of raspbian are you using?
    – Wilf
    Commented Dec 1, 2015 at 13:58
  • @Wilf: this is interesting - I saw both ways but did not know that the supplicant one is the way to go forward. As for my question, please see my answer - I found the issue (which is IMHO a bug)
    – WoJ
    Commented Dec 1, 2015 at 14:02

6 Answers 6

1

Open /etc/dhcp/dhclient.conf and input a line starting with supersede. This line makes sure that only the supplied list of values for domain-name-servers on it's right will be written inside /etc/resolv.conf when writing event happens.

Example:

supersede domain-name-servers 127.0.0.1, ::1;
2
  • This doesn't work on all RPI's... I wonder why?
    – 71GA
    Commented Feb 23, 2021 at 19:09
  • 1
    If this method does not work first edit the /etc/resolv.conf and dissable insert into a file using this command: chattr -V +i /etc/resolv.conf. To revert back use the command: chattr -i /etc/resolv.conf. (stackoverflow.com/questions/28860655/…)
    – 71GA
    Commented Feb 23, 2021 at 19:34
2

It looks like I found the issue. /bin/dhcpcd was still running despite no interfaces being configured via DHCP. The culprit is dhcpcd5.

Removing the package helped (and, surprise, something called openresolv was included)

root@rpi2:~# aptitude purge dhcpcd5
The following packages will be REMOVED:
  dhcpcd5{p} openresolv{u}

/etc/resolv.conf is not overwritten anymore.

3
  • 1
    With respect this is like solving a rattling noise problem in a car by removing the spare. dhcpcd is included in all recent releases of Raspbian, and removing it will break other features. If you don't want to use it you should disable in systemd. There is nothing wrong with configuring your Pi the old way, but you can set static with dhcpcd.
    – Milliways
    Commented Dec 1, 2015 at 22:14
  • @Milliways: could you please elaborate on break other features? dhcpd was installed on my system but a dhcpd.conf was not even present.
    – WoJ
    Commented Dec 2, 2015 at 7:23
  • 1
    dhcpcd is a complex program, and not without its problems. I think the Foundation adopted it because it automates networking (particularly WiFi) and allows easy setup from GUI. (Current GUI WiFi setup requires it.) I was initially not keen, but the fact that it allows zeroconf over link-local and thus ssh is a plus. It automatically handles changing network conditions without the complexity of wpa-roam. Lastly it is highly configurable, even if the documentation is a bit cryptic and technical. See the following for overview and read the man. wiki.archlinux.org/index.php/Dhcpcd
    – Milliways
    Commented Dec 2, 2015 at 7:52
2

Instead of removing dhcpcd and breaking a bunch of stuff, you could configure /etc/dhcpcd.conf (and probably /etc/init.d/dnsmasq) with your DNS information...

Just sayin'

1
  • On my setup of Raspbian GNU/Linux 10, adding the line resolvconf=NO to the file /etc/resolvconf.conf fixed this issue for me. Commented Feb 1, 2021 at 0:13
0

It may be simple as putting it's permissions to read-only.

sudo chmod 440 /etc/resolv.conf

But I would suggest to check again what is causing your resolv.conf to be overwritten as setting it to read-only may cause some other unexpected things.

1
  • But I would suggest to check again what is causing your resolv.conf to be overwritten - this is the essence of my question :)
    – WoJ
    Commented Dec 1, 2015 at 13:50
0

I found this similar question for Unix. The solution does not require to remove the dhcpd5 package.

However, I have not yet figured out where the config files for dhcpd are hiding on my Pi/Jessie. There are several suggestions here, I'll try the one where you add fixed DNS addresses at the end of the /etc/dhcpcd.conf.

Will keep you posted.

0

You could just disable the service resolved by entering: sudo systemctl disable systemd-resolved.service

1
  • You may want to use mask there instead of disable as this is something that is bound to be "required" by some other service (which implicitly enables it even if it was previously disabled).
    – goldilocks
    Commented Jan 7, 2022 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.