systemd-networkd daemon does not start the DHCP client

I have the appropriate network file with DHCP enabled.

$ cat /etc/systemd/network/20-dhcp.network 
[Match]
Name=enp3*

[Network]
DHCP=ipv4

[DHCP]
UseDomains=true

I have appropriate /etc/resolv.conf as well. I am not using systemd-resolvd daemon (and it may not have anything to do with it, because I did try using it, but did not help anyway). Any ideas why the DHCP client needs to be run manually to get it working?


Solution 1:

Just in case people aren't aware - systemd-networkd now contains its own in-built DHCP client implementation so no external DHCP clients would be started unless they're configured elsewhere.

The configuration is controlled by a number of configuration files as described in the systemd-networkd man page. With Ubuntu18.04 network configuration (/{lib,etc,run}/netplan/*.yaml) is now controlled by netplan which will generate configuration files for systemd-networkd (/{lib,etc,run}/systemd/network/).

Specifically the DHCP client operation is controlled in the systemd.network config file - it can be enabled in the [NETWORK] section of the config file using the DHCP directive (it defaults to "no") and configured the [DHCP] section.

Solution 2:

From reading man systemd.network, it sounds like the .network files in /etc/systemd/network are controlled by systemd-networkd. If the files aren't being read, it could be that you aren't using this part of systemd.

For example, on a Ubuntu 16.04 desktop, I can see that systemd-networkd is not in use:

 systemctl status systemd-networkd

● systemd-networkd.service - Network Service Loaded: loaded (/lib/systemd/system/systemd-networkd.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:systemd-networkd.service(8)

Instead, the NetworkManager service is running. So, a DHCP client would be configured through NetworkManager in that case, or NetworkManager needs to be stopped and disabled, and systemd-networkd needs to be started and enabled.

Solution 3:

It turned out that I had two network files. I followed arch linux systemd-networkd documentation (https://wiki.archlinux.org/index.php/systemd-networkd#Wireless_adapter), and created one network file:

/etc/systemd/network/25-wireless.network
[Match]
Name=wlp2s0

[Network]
DHCP=ipv4

And it is working.