9

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
e-pirate
  • 133

8 Answers8

4

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.

slangasek
  • 5,828
3

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

1

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!

heynnema
  • 73,649
1

Have you tried static settings

A simple edit to /etc/NetworkManager/NetworkManager.conf and disabling systemd-resolved.service (as in this answer https://askubuntu.com/a/907249/719422). But that alone, while essential, does not guarantee tamper-proof resolv.conf.

Do this as SuperUser:

echo nameserver 8.8.8.8 > /etc/resolv.conf
chattr -e /etc/resolv.conf
chattr +i /etc/resolv.conf
0

There actually a lot of confusion between netplan(/etc/netplan/*.yaml), systemd-resolved(/etc/systemd/resolved.conf) and /etc/resolv.conf. When configuring the network with netplan, if ping pass but the domain resolve failed, check /run/systemd/resolve/resolv.conf, this file is usually generated from /etc/systemd/resolved.conf. Latest ubuntu using netplan to configure network, while the older use /etc/network/interfaces

0

I have the same problem on Ubuntu Server 20.04. (Unlike Desktop, Server does not use NetworkManager, so the answer to a related question for Desktop does not apply: https://askubuntu.com/a/907249/644076)

The network is configured using netplan. I disabled and stopped systemd-resolved because my router's DNS works just fine and I do not want additional complications from systemd-resolved, which I have experienced many times. Because systemd-resolved was gone, I also removed the symlink /etc/resolv.conf that pointed to /run/systemd/resolve/stub-resolv.conf.

But when I restarted systemd-networkd, /etc/resolv.conf did not get created.

Thanks to inspiration from another answer (https://askubuntu.com/a/1241298/644076), I installed the resolvconf package and it just works. I did not configure anything and a symlink /etc/resolv.conf pointing to /run/resolvconf/resolv.conf with the correct content appeared.

Syncopated
  • 405
  • 2
  • 6
  • 11
0

I had the same problem (Ubuntu 22.04 LTS Server and Desktop) and I was looking for any solutions. I tested the @Syncopated solution but it doesn't work in my case. I followed this mini-guide (in Spanish) and I got it.

You have to erase the /etc/resolv.conf and copy it from /run/systemd/resolve/resolv.conf. Similar to the way that other partners were saying but, at least in my case, with a different source.

$ sudo rm -f /etc/resolv.conf

$ sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

sotirov
  • 4,379
0

In Ubuntu 24.04 I found NetworkManager stuck the nameserver info in /run/NetworkManager/no-stub-resolv.conf so a symbolic link to it in /etc/resolv.conf did the trick

ln -s /run/NetworkManager/no-stub-resolv.conf /etc/resolv.conf
muru
  • 207,228
Mischa
  • 21