/etc/network/interfaces does not overwrite /etc/resolv.conf

5,428

As stated in my question, the configuration is accurate according to the Ubuntu documentation. However, ifdown and ifup did not work. After half a day of googling around, I gathered enough clues to find a solution.

TL;DR;

Comment out (or remove) the lines from /etc/network/interfaces.d/eth0 that originally was:

auto eth0
iface eth0 inet dhcp

The long answer:

I'm sorry I cannot provide an explanation as to why I had this problem. I know too little of Linux. /: The problem seems to be that resolvconf, which is triggered when booting (I think), was unable to correctly update /etc/resolv.conf because it found the same interface twice: once in /etc/network/interfaces.d/eth0 and once in my custom configuration /etc/network/interfaces.

Restarting the network service gave me this:

ubuntu@pinex:~$ sudo service networking restart
Job for networking.service failed because the control process exited with error code. See "systemctl status networking.service" and "journalctl -xe" for details.
ubuntu@pinex:~$ systemctl status networking.service
● networking.service - Raise network interfaces
   Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
  Drop-In: /run/systemd/generator/networking.service.d
           └─50-insserv.conf-$network.conf
   Active: failed (Result: exit-code) since Mon 2016-12-19 13:59:48 CET; 10s ago
     Docs: man:interfaces(5)
  Process: 2433 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
  Process: 2428 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environm
 Main PID: 2433 (code=exited, status=1/FAILURE)

Dec 19 13:59:47 pinex ifup[2433]: DHCPACK of 192.168.0.18 from 192.168.0.1
Dec 19 13:59:47 pinex ifup[2433]: RTNETLINK answers: File exists
Dec 19 13:59:47 pinex dhclient[2446]: bound to 192.168.0.18 -- renewal in 4214 seconds.
Dec 19 13:59:47 pinex ifup[2433]: bound to 192.168.0.18 -- renewal in 4214 seconds.
Dec 19 13:59:48 pinex ifup[2433]: RTNETLINK answers: File exists
Dec 19 13:59:48 pinex ifup[2433]: Failed to bring up eth0.
Dec 19 13:59:48 pinex systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Dec 19 13:59:48 pinex systemd[1]: Failed to start Raise network interfaces.
Dec 19 13:59:48 pinex systemd[1]: networking.service: Unit entered failed state.
Dec 19 13:59:48 pinex systemd[1]: networking.service: Failed with result 'exit-code'.

I remember seeing something about the /etc/network/interfaces.d/eth0 when googling around. When commenting out those lines, restarting the network service worked fine. However, the /etc/resolv.conf was still the same as before...

I had to do the following:

ubuntu@pinex:~$ sudo resolvconf -u
/etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /run/resolvconf/resolv.conf
ubuntu@pinex:~$ sudo rm /etc/resolv.conf
ubuntu@pinex:~$ sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf

That updated the /etc/resolv.conf to my expected values! After a reboot of the device, the file was automatically properly populated!

I hope this is of help to someone else as well! And, if anyone can explain the problem, that would be appreciated. (:

Share:
5,428

Related videos on Youtube

Reyhn
Author by

Reyhn

Updated on September 18, 2022

Comments

  • Reyhn
    Reyhn over 1 year

    I'm a Linux novice experimenting with setting up a DNS cache server on a Pine64 on Ubuntu 16.04. I'm trying to set up a static IP-address with a a local Bind9 DNS-server. I've followed this great tutorial, and looked at several others.

    However, I'm having trouble with getting the changes in /etc/resolv.conf to stick. /: When I reboot, the settings in /etc/network/interfaces are not written to /etc/resolv.conf.

    This is my /etc/network/interfaces:

    # interfaces(5) file used by ifup(8) and ifdown(8)
    # Include files from /etc/network/interfaces.d:
    source-directory /etc/network/interfaces.d
    
    # Disable wlan1 by default (8723bs has two intefaces)
    iface wlan1 inet manual
    
    # Loopback interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto eth0
    iface eth0 inet static
            address 192.168.0.18
            netmask 255.255.255.0
            gateway 192.168.0.1
            dns-nameservers 192.168.0.18
            dns-search green.intra
    

    This is my /etc/default/bind9:

    # run resolvconf?
    RESOLVCONF=yes
    
    # startup options for the server
    OPTIONS="-4 -u bind"
    

    From those two files, I was under the impression that the /etc/resolv.conf should become this (automatically, upon booting):

    # 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.0.18
    search green.intra
    

    ...but instead it becomes 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 83.255.255.1
    nameserver 83.255.255.2
    search home
    

    If I add my desired settings to /etc/resolv.conf, everything works as I expect, until I reboot.

    What am I doing wrong?

    Edit: I have RTFM in trying to figure this out:

    https://help.ubuntu.com/14.04/serverguide/dns-troubleshooting.html
    https://help.ubuntu.com/12.04/serverguide/network-configuration.html
    https://help.ubuntu.com/14.04/serverguide/dns-configuration.html

    Edit: ifup and ifdown fail: As suggested in the answer to the proposed duplicate question, using service networking restart might not be reliable in this situation. Instead, I tried the following:

    ubuntu@pinex:~$ sudo ifdown -v eth0
    Reading directory /etc/network/interfaces.d
    Parsing file /etc/network/interfaces.d/eth0
    ifdown: interface eth0 not configured
    

    and:

    ubuntu@pinex:~$ sudo ifdown -v eth0
    Reading directory /etc/network/interfaces.d
    Parsing file /etc/network/interfaces.d/eth0
    ifdown: interface eth0 not configured
    ubuntu@pinex:~$ sudo ifup -v eth0
    Reading directory /etc/network/interfaces.d
    Parsing file /etc/network/interfaces.d/eth0
    Configuring interface eth0=eth0 (inet)
    /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
    run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
    
    /sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0
    Internet Systems Consortium DHCP Client 4.3.3
    Copyright 2004-2015 Internet Systems Consortium.
    All rights reserved.
    For info, please visit https://www.isc.org/software/dhcp/
    
    Listening on LPF/eth0/36:c9:e3:f1:b8:05
    Sending on   LPF/eth0/36:c9:e3:f1:b8:05
    Sending on   Socket/fallback
    DHCPREQUEST of 192.168.0.18 on eth0 to 255.255.255.255 port 67 (xid=0x79b015c0)
    DHCPACK of 192.168.0.18 from 192.168.0.1
    RTNETLINK answers: File exists
    bound to 192.168.0.18 -- renewal in 5280 seconds.
    /bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
    run-parts: executing /etc/network/if-up.d/000resolvconf
    run-parts: executing /etc/network/if-up.d/bind9
    run-parts: executing /etc/network/if-up.d/openssh-server
    run-parts: executing /etc/network/if-up.d/upstart
    run-parts: executing /etc/network/if-up.d/wpasupplicant
    Configuring interface eth0=eth0 (inet)
    /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
    run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
    /bin/ip addr add 192.168.0.18/255.255.255.0 broadcast 192.168.0.255       dev eth0 label eth0
    RTNETLINK answers: File exists
    Failed to bring up eth0.
    

    ... which led me to the answer (see below).