make netplan write resolve.conf

15,498

Solution 1

It is a deliberate design decision that netplan delegates management of resolver configuration to systemd-resolved. There is no support in netplan for directly managing /etc/resolv.conf based on answers to dhcp queries. Indeed, systemd-networkd expects to pass this information to systemd-resolved and netplan relies on this behavior.

Solution 2

There appears to be a lot of confusion between resolvconf, systemd-resolved and /etc/resolv.conf. Here's my 2 cents:

Ubuntu 18.04 uses systemd-resolved for name resolution. As @slangasek correctly pointed out, netplan delegates name resolution to systemd-resolved. For systemd-resolved to work properly, /etc/resolv.conf needs to point to /run/systemd/resolve/stub-resolv.conf.

However, if you also have the resolvconf package installed on the system, the symlink /etc/resolv.conf will incorrectly point to /run/resolvconf/resolv.conf. This will result in name resolution failures, e.g. "Temporary failure in name resolution" error. Manual editing of /etc/resolv.conf is not recommended. The simplest resolution is to remove the resolvconf package. This will reset the symlink and all will be well (you may require a reboot or at least restart the systemd-resolved service).

Solution 3

I see it a lot. Users have removed the symlink for /etc/resolv.conf, and put a hand-written file there. There's actually three different places that this symlink refers to, and I'll give you the most common one...

In terminal...

cd /etc # change directory

sudo mv resolv.conf resolv.conf.BAK # rename the current resolv.conf as a backup file

sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf # recreate standard symlink

Note: do not manually edit /etc/resolv.conf!

Share:
15,498

Related videos on Youtube

e-pirate
Author by

e-pirate

Updated on September 18, 2022

Comments

  • e-pirate
    e-pirate over 1 year

    I have an Odroid C2 - a single board computer running 18.04 minimal for ARM. Originally, it was using NetworkManager + systemd-resolved to manage network connections, but since I use only Ethernet and always connected to the same network, I find it a little bit overkill, so I disable both of them and moved to Netplan. Here is my /etc/netplan/02-networkd.yaml:

    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: yes
    

    As you can see, it is a simple DHCP configuration. Here is the result of using that config:

    # netplan ip leases eth0
    ADDRESS=10.0.0.4
    NETMASK=255.255.255.0
    ROUTER=10.0.0.1
    SERVER_ADDRESS=10.0.0.1
    T1=7200
    T2=12600
    LIFETIME=14400
    DNS=10.0.0.1
    NTP=10.0.0.1
    DOMAINNAME=vault
    CLIENTID=fff75f76ac00020000ab11a7b5e398b7e20ac7
    

    IP address and all interface parameters set correct. The only problem I have is with DNS. I found that netplan does not update /etc/resolve.conf even it has all obligatory information in the leas.

    Is there a way to make Netplane update/configure /etc/resolve.conf with DNS information it receives from DHCP without using NetworkManager or resolved? Here is some additional info:

    # ls -lA /etc/resolv.conf
    -rw-r--r-- 1 root root 20 Apr 21 00:13 /etc/resolv.conf
    
    # cat /etc/resolv.conf 
    nameserver 10.0.0.1
    search vault
    
    • Boris Hamanov
      Boris Hamanov about 5 years
      Edit your question and show me ls -al /etc/resolv.conf and cat /etc/resolv.conf and resolvectl (or system-resolve --status). Start comments to me with @heynnema or I may miss them.
    • e-pirate
      e-pirate about 5 years
      @heynnema current resolv.conf is just a regular hand-written file. It seems that this installation is missing both resolvectl and system-resolve.
    • Boris Hamanov
      Boris Hamanov about 5 years
      Oops. A typo by me. The correct command is systemd-resolve --status. Give me a couple of minutes to put together a quick answer for you. Are you using VPN?
    • e-pirate
      e-pirate about 5 years
      @heynnema the systemd-resolved is down, my question is how to make netplan manage resolve.conf without external services like resolved and NetworkManager.
    • Boris Hamanov
      Boris Hamanov about 5 years
      Did you disable systemd-resolved? I just looked back and I see that you did. That and/or dnsmasq manage DNS, and /etc/resolv.conf.
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy about 5 years
      Specify Network Manager as renderer for netplan config - if NM handles resolv.conf file, then that's what you want to use then
  • e-pirate
    e-pirate about 5 years
    So, I need a whole service just to maintain a single file in up to date state? Why?
  • e-pirate
    e-pirate about 5 years
    systemd-resolved mast be up for the method, while I want to get rid of any 'external' services and make netplan manage resolev.conf by itself.
  • Boris Hamanov
    Boris Hamanov about 5 years
    @e-pirate doesn't work that way... and... you use dhcp4, so you do rely on external services now.
  • e-pirate
    e-pirate about 5 years
    DHCP client is a mast-have in that chain, as well as something to handle interface configuration on the client side, while resolved is just a mediator between dhcp and resolv.conf. In Gentoo I don't need any external service to the system, that manages network interfaces (ipupdown AFAIR), it will write data from dhcp lease to resolv.conf. I expected netplan to handle that, but it seems that netplan needs an external DNS handler like resolved.
  • slangasek
    slangasek about 5 years
    The function of systemd-resolved is not to maintain /etc/resolv.conf. The function of systemd-resolved is to make it unnecessary to maintain /etc/resolv.conf, because having a resolv.conf file that changes makes name resolution unreliable across the life cycle of a system (especially for e.g. long-lived chroots, containers, etc), and also a local resolver is capable of detecting when an upstream nameserver is down and provide better behavior when compared with the in-process glibc behavior.