sim_tcr
Posts: 331
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

changes on /etc/resolve.conf not getting saved upon reboot

Sat Oct 05, 2013 8:21 am

Hello,

I am running 2013-09-25-wheezy-raspbian image on 4GB SD Card. I tried making changes to /etc/resolv.conf (adding two name servers).

Upon reboot those values are gone.

Any idea?

Thanks,
Simon Mandy
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

User avatar
DougieLawson
Posts: 39219
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: changes on /etc/resolve.conf not getting saved upon rebo

Sat Oct 05, 2013 8:59 am

You can't just use nano (or vi) on /etc/resolv.conf. That will be overwritten every time you disconnect, reconnect, shutdown or reboot. Resolv.conf is updated by the ifup/ifdown process based on what's in your /etc/network/interfaces definitions.

Edit /etc/network/interfaces and add your preferred nameserver (my examples use Google's public servers)

Code: Select all

iface eth0 inet dhcp
  dns-nameservers 8.8.8.8 8.8.4.4

and the same for WLAN0

Code: Select all

iface wlan0 inet dhcp
  dns-nameservers 8.8.8.8 8.8.4.4
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
jojopi
Posts: 3272
Joined: Tue Oct 11, 2011 8:38 pm

Re: changes on /etc/resolve.conf not getting saved upon rebo

Sat Oct 05, 2013 9:28 am

Also, if you are using DHCP, it would be better to configure your DHCP server/router to give out the resolvers you want to use, instead of individually configuring your clients to substitute their own.

sim_tcr
Posts: 331
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

Re: changes on /etc/resolve.conf not getting saved upon rebo

Sat Oct 05, 2013 11:37 am

DougieLawson wrote:You can't just use nano (or vi) on /etc/resolv.conf. That will be overwritten every time you disconnect, reconnect, shutdown or reboot. Resolv.conf is updated by the ifup/ifdown process based on what's in your /etc/network/interfaces definitions.

Edit /etc/network/interfaces and add your preferred nameserver (my examples use Google's public servers)

Code: Select all

iface eth0 inet dhcp
  dns-nameservers 8.8.8.8 8.8.4.4

and the same for WLAN0

Code: Select all

iface wlan0 inet dhcp
  dns-nameservers 8.8.8.8 8.8.4.4

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

auto wlan0
iface wlan0 inet static
address 192.168.1.XXX
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
dns-nameservers 8.8.8.8 8.8.4.4

auto eth0
iface eth0 inet static
address 192.168.1.XXX
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
dns-nameservers 8.8.8.8 8.8.4.4
Is this correct?
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

User avatar
DougieLawson
Posts: 39219
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: changes on /etc/resolve.conf not getting saved upon rebo

Tue Oct 08, 2013 7:45 am

That should work.

The dns-nameservers statement relates to the iface stanza that comes before it. That means you can have different specifications depending on which interface is connected.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

sim_tcr
Posts: 331
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

Re: changes on /etc/resolve.conf not getting saved upon rebo

Tue Oct 08, 2013 7:51 am

DougieLawson wrote:That should work.

The dns-nameservers statement relates to the iface stanza that comes before it. That means you can have different specifications depending on which interface is connected.
After making those changes, if i look in /etc/resolve.conf will it be there?
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

pippopippo
Posts: 17
Joined: Mon Mar 07, 2016 12:30 pm

Re: changes on /etc/resolve.conf not getting saved upon rebo

Fri Apr 08, 2016 1:09 pm

Hi,

this is my network/interfaces:

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.113
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
dns-nameservers 8.8.8.8 4.4.4.4


auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
metric 1
dns-nameservers 8.8.8.8 4.4.4.4



allow-hotplug eth1
iface eth1 inet dhcp
metric 2

-------
but dns is not ok:

nslookup google.com
;; Got recursion not available from 192.168.8.1, trying next server
Server: 8.8.8.8
Address: 8.8.8.8#53

and:

wget google.com
--2016-04-08 03:10:51-- http://google.com/
Resolving google.com (google.com)... 192.168.8.1
Connecting to google.com (google.com)|192.168.8.1|:80... connected.
HTTP request sent, awaiting response... 307 Temporary Redirect
Location: http://192.168.8.1/html/index.html?url=google.com [following]
--2016-04-08 03:11:06-- http://192.168.8.1/html/index.html?url=google.com

------

my /etc/resolv.conf is this:

# 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
nameserver 192.168.8.1
nameserver 8.8.8.8
nameserver 4.4.4.4
search hi.link



and it is not correct...nameserver 192.168.8.1 is not correct...it cames from eth1 interfaces that is a 3G dongle connected but non working now....it should be:

# 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
nameserver 8.8.8.8
nameserver 4.4.4.4


---if I change by hand /etc/resolv.conf everything works fine but at the next restart it came back (wrong).

How can I change /etc/resolv.conf forever?

tks,

Pippo

User avatar
DougieLawson
Posts: 39219
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: changes on /etc/resolve.conf not getting saved upon rebo

Sat Apr 09, 2016 1:13 pm

You need to remove the raspberrypi-net-mods and resolvconf packages if they're installed. The network-manager stuff should then work more normally and your changes to the /etc/network/interfaces file will be effective.

Your alternative option is to embrace the changes from those two packages and remove the stuff you've added in /etc/network/interfaces and add stuff in /etc/dhcpcd.conf to define your static IP and the resolver you want to use.

I've added a couple of lines to define "domain" and "search" in my /etc/resolv.conf so this is my interfaces file

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual
        dns-search example.co.uk
        dns-domain example.co.uk

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
        dns-search example.co.uk
        dns-domain example.co.uk

#allow-hotplug wlan1
#iface wlan1 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
and add this stuff at the bottom of /etc/dhcpcd.cond

Code: Select all

interface eth0
static ip_address=192.168.1.99/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
#
interface wlan0
static ip_address=192.168.1.29/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

cotuitKayaker
Posts: 1
Joined: Tue Jan 30, 2018 10:38 am

Re: changes on /etc/resolve.conf not getting saved upon reboot

Tue Jan 30, 2018 10:51 am

I wanted to add this for people who are using RaspberryPi with Firebase to access data. I wrote my python test code on win10 using the firebase_admin library. Everything worked fine. However when I moved my python code over to the RaspberryPi Zero W (RaspianOS), and attempted a get() from the cloud based data, I got the following errors:

google.auth.exceptions.TransportError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb5d4ee50>: Failed to establish a new connection: [Errno 111] Connection refused',))

To resolve this, in /etc/resolve.conf, you must change:

# Generated by resolvconf
nameserver 127.0.0.1

to:

# Generated by resolvconf
nameserver 8.8.8.8

Also, make the changes listed in the forum posts above to ensure that your conf file does not get automatically overwritten.

teknopaul
Posts: 5
Joined: Sun Apr 26, 2015 1:51 am

Re: changes on /etc/resolve.conf not getting saved upon reboot

Sun Nov 18, 2018 6:37 pm

Testing this on Raspbian/stretch to take back control of resolv.conf and local DNS lookups with a static networking config.

- disable dhcpcd which fiddles with resolv.conf
- tell NetworkManager not to
- configure network without dhcpcd
- configure resolv.conf manually
- remove systemd-resolved
- remove root access to resolv.conf

Manual network config

**/etc/network/interfaces**

Code: Select all

    iface enxb8123442be inet static
        address 192.168.1.99
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers 208.67.222.222
        dns-search example.org
The above config will generate resolv.conf, potentially as you needed it.

**resolv.conf**

Code: Select all

	nameserver 208.67.222.222
	search example.org
In my case it still gets the dns servers wrong 127.0.0.1, resolvconf is presuming systemd's local cache is running. I run dnsmasq on this server as a local cache for the network. This is apparently a "bug" that just happens to make systemd-resolved necessary.

The following should tell network manager not to fiddle with resolv.conf, but in raspbian did not, YMMV.

**/etc/NetworkManager/NetworkManager.conf**

Code: Select all

	[main]
	dns=none
I've seen it as follows, but this did not work in raspbian either
dns=default


So now prevent even root access to resolv.conf

Code: Select all

    chattr +i /etc/resolv.conf
If you script your own /etc/resolv.conf add to the script

Code: Select all

    chattr -i /etc/resolv.conf
    ...
    chattr +i /etc/resolv.conf
To start network on boot the simplest way is to add to

**/etc/rc.local**

Code: Select all

    ifup enxb8123442be
n.b. you may need to make /etc/rc.local executable

Tell systemd not to run dhcpcd (we have a static config), and disable systemd's DNS meddling.

Code: Select all

    sudo systemctl disable dhcpcd
    sudo systemctl disable --now systemd-resolved.service
reboot or restart networking

Code: Select all

    sudo systemctl enable networking

User avatar
Roken
Posts: 371
Joined: Sun Dec 31, 2017 4:35 pm
Location: UK

Re: changes on /etc/resolve.conf not getting saved upon reboot

Sun Nov 18, 2018 8:31 pm

Easy answer. Setup /etc/resolv.conf how you want it.

Run

Code: Select all

sudo chattr +i /etc/resolv.conf
Then it will never be changed. If you need to edit it, change +i to -i
Headless PI. OMG, someone cut it's head off. Oh, hang on. it didn't have one to start with.

Return to “General discussion”